471,078 Members | 812 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

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


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,
May 21 '09 #1
1 5043
374 256MB
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 = ""
  11.         report.Load(Application.StartupPath + "\Reports\ForcedPay.rpt")
  12.         CrystalReportViewer1.ReportSource = report
  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
May 26 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by suicidaltendencies | last post: by
9 posts views Thread by Bijoy Naick | last post: by
3 posts views Thread by ralphdepping | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.