Skip to Content
0
Former Member
Apr 02, 2013 at 06:06 PM

VS2008/CR2008 - changing the database dynamically

16 Views

I am new to Crystal Reporting so I am still learning the ropes of it. I've been researching this problem for a couple of months and every possible solution has failed. I am using:

  • VS2008 v9.0.21022.8 RTM
  • .NET Framework v3.5 SP1
  • CR2008 v12.3.0.601 product type FULL
  • Oracle Server connections

I have a CR using a stored procedure that is connected via the Oracle Server - test database connection. The report works correctly in VS using the test database login info in the web.config file.

Next, I added the report to the VS application using the production database connection. However, the CR still wants to connect to the test database even though the web.config file login information is for the production database. I don't want to create a CR for each connection but unless I can find a solution that will dynamically change the stored procedure connection, I will have no choice. Hopefully, there is a solution. Here is the latest code I am using to change the database connection dynamically:

Public Sub setCrptLogon(ByVal psCRptFileName As String)
Dim z As EventArgs = Nothing

myReportDocument.Load("\\CrystalReports\Birthday_Cards.rpt") 'psCRptFileName


Dim connCrRpt As New ConnectionInfo()

connCrRpt.ServerName = System.Web.Configuration.WebConfigurationManager.AppSettings.Item("ncir_server")
connCrRpt.DatabaseName = System.Web.Configuration.WebConfigurationManager.AppSettings.Item("ncir_server")
connCrRpt.UserID = System.Web.Configuration.WebConfigurationManager.AppSettings.Item("ncir_user")
connCrRpt.Password = System.Web.Configuration.WebConfigurationManager.AppSettings.Item("ncir_password")

Dim crtables As Tables = myReportDocument.Database.Tables
Dim crtable As Table

For Each crtable In crtables 'myReportDocument.Database.Tables
Dim logOnInfo As TableLogOnInfo = crtable.LogOnInfo
logOnInfo.ConnectionInfo = connCrRpt
crtable.ApplyLogOnInfo(logOnInfo)
Next

RaiseEvent GetCrystalReportParameters(strStProcName, z)
uc_CReports.ptyCR_Viewer.ReportSource = myReportDocument
End Sub

When I step through the Sub, the only table in crtables is the stored procedure for the report which is correct. However, I can't change the database information for it dynamically. Any suggestions?

Thanks!