0
votes

I only just started working with Visual Studio 2012, and never had any training, so forgive me is this is a simple/stupid question.

I created a relatively simple program, that users can use to run Crystal Reports. They can select their department, and get a list with possible reports. If they click on the button "select", a second form opens up with the Crystal Report.

However, when this comes up, it is asking for the database login. I created 3 variables in my main screen, saving the database name, username and password, and want to use this when opening my report.

The report is based on an Oracle database

The form that holds the Crystal file has a CrystalReportViewer in it. In here, I selected my report.

The code that I've found online isn't working yet, it is still asking for the login details:

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

 Public Class F_QTS_Al4All

Private Sub configureCRYSTALREPORT()
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub

Private Sub setDBLOGONforREPORT(ByVal myconnectioninfo As ConnectionInfo)
    Dim mytableloginfos As New TableLogOnInfos()
    mytableloginfos = CrystalReportViewer1.LogOnInfo
    For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
        myTableLogOnInfo.ConnectionInfo = myconnectioninfo
    Next
End Sub

Private Sub CrystalReportViewer1_Load(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Load

End Sub
End Class

So I've been playing around a little bit, and moved copied the myConnectionInfo part also to the CrystalReportViewer1 part. Now, I am getting an exception saying NullReferenceException was unhand-led by user code

I am running out of idea's, would any of you have an idea on how to change to code so it doesn't ask for credentials anymore?

I also read somewhere that I could keep the report source empty, but I am not sure how to call the report if I leave it empty?

Thanks a lot in advance

Kind regards

Gerben

1

1 Answers

0
votes

I found out how to do this. I created another shared variable in my main screen called reportpath. I fill this is when I decide which report I need to call. After that I have the following code.

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Class F_Report

Private Sub configureCRYSTALREPORT()
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub

Private Sub setDBLOGONforREPORT(ByVal myconnectioninfo As ConnectionInfo)
    Dim mytableloginfos As New TableLogOnInfos()
    mytableloginfos = CrystalReportViewer1.LogOnInfo
    For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
        myTableLogOnInfo.ConnectionInfo = myconnectioninfo
    Next
End Sub

Private Sub CrystalReportViewer1_Load(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Load
    CrystalReportViewer1.ReportSource = F_IJ_IE_Internal_Reporting.ReportPath
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub
End Class