Connecting Tech Pros Worldwide Help | Site Map

Logon Failed,Description:Invalid authorization specification error in crystal report

Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#1: May 21 '09
Hi,

I am new to .NET.I have created a desktop application in C#.NET that has Crystal reports used in it. This all works fine when I log in on the "EVERY" as servername which is the default name of my machine and also SQL SERVER name. However when I run it on another machine it does not work.It expect "EVERY" server.It should expect because the name of the sql server is that.
If I specify the servername as local while generating report then it is unable to identify the database name and generate the following error:

Logon Failed
Description:Invalid authorization specification

while If I use "EVERY" as server name then it works fine on my system but unable to run on another machine...
I want to know that how to remove such error so that my reports works well on every machine.Please specify me the whole procedure...I have already searched alot but unable to grasp the solution of the problem..

I am expecting answer as soon as possible...
Thanks and regards,
bye
OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 353
#2: May 26 '09

re: Logon Failed,Description:Invalid authorization specification error in crystal report


You need to change the server and login information of the crystal reports in code.
what i do is retrieve the current servername from each pc
Expand|Select|Wrap|Line Numbers
  1. Dim sqlcon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\sqlexpress;Initial Catalog='" & strCompanyName & "';Integrated Security=True")
  2.         Dim sqlCOm As SqlCommand = New SqlCommand("select @@servername", sqlcon)
  3.         sqlcon.Open()
  4.         strOldServerName = sqlCOm.ExecuteScalar
  5.         sqlcon.Close()
I then use that name as the new servername.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report()
  2.         Dim report As New ReportDocument
  3.         Dim connection As IConnectionInfo
  4.         Dim oldServerName As String = "OLD SERVERNAME"
  5.         Dim oldDatabaseName As String = "OLD DATABASENAME"
  6.         Dim newServerName As String = strOldServerName
  7.         Dim newDatabaseName As String = NEWDATABASENAME
  8.         Dim UserID As String = ""
  9.         Dim Password As String = ""
  10.  
  11.         report.Load(Application.StartupPath + "\Reports\ForcedPay.rpt")
  12.         CrystalReportViewer1.ReportSource = report
  13.  
  14.         'Change the server name and database in main report
  15.         For Each connection In report.DataSourceConnections
  16.             report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  17.         Next
  18.         'Change the server name and database subreports
  19.         Dim subreport As ReportDocument
  20.         For Each subreport In report.Subreports
  21.             For Each connection In subreport.DataSourceConnections
  22.                 If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  23.                    And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  24.                     subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  25.                 End If
  26.             Next
  27.         Next
  28.         CrystalReportViewer1.RefreshReport()
  29.     End Sub
Reply