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
- 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.
- 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