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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swatii
    New Member
    • May 2009
    • 15

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

    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:Inv alid 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
    Contributor
    • Jan 2008
    • 374

    #2
    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
    Code:
    Dim sqlcon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\sqlexpress;Initial Catalog='" & strCompanyName & "';Integrated Security=True")
            Dim sqlCOm As SqlCommand = New SqlCommand("select @@servername", sqlcon)
            sqlcon.Open()
            strOldServerName = sqlCOm.ExecuteScalar
            sqlcon.Close()
    I then use that name as the new servername.
    Code:
    Private Sub Report()
            Dim report As New ReportDocument
            Dim connection As IConnectionInfo
            Dim oldServerName As String = "OLD SERVERNAME"
            Dim oldDatabaseName As String = "OLD DATABASENAME"
            Dim newServerName As String = strOldServerName
            Dim newDatabaseName As String = NEWDATABASENAME
            Dim UserID As String = ""
            Dim Password As String = ""
    
            report.Load(Application.StartupPath + "\Reports\ForcedPay.rpt")
            CrystalReportViewer1.ReportSource = report
    
            'Change the server name and database in main report
            For Each connection In report.DataSourceConnections
                report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
            Next
            'Change the server name and database subreports
            Dim subreport As ReportDocument
            For Each subreport In report.Subreports
                For Each connection In subreport.DataSourceConnections
                    If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
                       And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
                        subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
                    End If
                Next
            Next
            CrystalReportViewer1.RefreshReport()
        End Sub

    Comment

    Working...