Hello,
I have VB.Net 2008 with Crystal Reports. I have a large project with 200 .rpt files where the Crystal Report -> Database -> Set Datasource Location was used to point these reports to a TEST database (this works great).
Now I want to move this project to PRODUCTION and I don't want to have to touch each report manually, I want to do this in VB.Net code page.
When I step through the code, it shows the correct database, passwords and tables - everything looks good so I know my connection string is good.
The problem is when I run it I get table not found error and the .rpt file still shows the original manually configured values.
If I look at the .rpt file using Crystal Report -> Database -> Set Datasource Location, it still shows the TEST database.
What code do I have to add in VB.Net to be able to move between TEST and PRODUCTION without having to manual touch each of the 200 reports?
' vb code behind
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim SConn As System.Data.SqlClient.SqlConnectionStringBuilder = New System.Data.SqlClient.SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString)
rpt = New ReportDocument()
rpt.Load("TestReport.rpt")
rpt.SetDatabaseLogon(SConn.UserID, SConn.Password, SConn.DataSource, SConn.InitialCatalog)
With crConnectionInfo
.ServerName = SConn.DataSource
.DatabaseName = SConn.InitialCatalog
.UserID = SConn.UserID
.Password = SConn.Password
End With
CrTables = rpt.Database.Tables
' Update the source of all the tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
CrystalReportViewer1.ReportSource = rpt
' asp front page
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" HasRefreshButton="True" EnableDrillDown="false"
DisplayGroupTree="False" ReuseParameterValuesOnRefresh="True" EnableDatabaseLogonPrompt="false" />
Thanks in advance,
Sonya