Home > Mobile >  Crystal report Viewer keeps on Asking for Logon ID and Password at runtime
Crystal report Viewer keeps on Asking for Logon ID and Password at runtime

Time:10-24

Situation:

I made application using vb.net ,ms access and crystal report

When I run it my computer, I don't encounter any problem at all , but when I install and run it on other computer, crystal report asks for login ID and password

I have 2 tables in the report

The main report and the sub report

the Datasource for my rpt file is:

Datasource:C:\User\Documents\report.accdb

some suggests doing something like this: myreport.SetDatabaseLogon.("user","password")

But I dont know how to use it and where to input the code

Anyone Familiar with this ? Thank you

CodePudding user response:

I just wanted to provide you with the code that I used when I needed to connect to crystal reports embedded within my Visual Studio project.

Please disregard if you are not using the same method.

In my example, I connect to a SQL database so that the stored procedure my crystal report is using can be loaded.

I always used these subroutines to create a crystal report connection and configure the report with proper settings.

I'm not sure if you can set the connectioninfo with just a userID and password, but I figured this code might give you some ideas about what your code is missing.

If you need more help, please provide code snippets so we can help further diagnose.

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

'Crystal Report Here
Private mycrystalreport1 As CrystalReport1

Private Sub ConfigureCrystalReports()
    Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
    mycrystalreport1 = New CrystalReport1()
    Dim reportPath As String = Application.StartupPath & "\" & "CrystalReport1.rpt"
    mycrystalreport1.Load(reportPath)
    CrystalReportViewer1.ReportSource = mycrystalreport1
    myConnectionInfo.ServerName = "SQL" 'OR WHATEVER SERVER NAME IS
    myConnectionInfo.DatabaseName = "DATABASE_NAME"
    myConnectionInfo.UserID = "USER_ID"
    myConnectionInfo.Password = "PASSWORD"
    SetDBLogonForReport(myConnectionInfo, mycrystalreport1)
End Sub

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
    Try
        Dim myTables As Tables = myReportDocument.Database.Tables
        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
            Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
            myTableLogonInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(myTableLogonInfo)
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ConfigureCrystalReports()
    
    'CAN SET PARAMETERS FOR A STORED PROCEDURE OR LOCAL VARIABLES IN CRYSTAL HERE
    
End Sub

Hopefully, this can provide you with some insight as to how crystal reports can take in a username and password.

CodePudding user response:

Change your report to use ODBC. Makes it easier to check the database connection on each PC. I'm guessing that the 2nd PC doesn't have the required database drivers to connect to accdb, but that's just a guess.

  • Related