 | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| |
| re: Crystal Report connection to SQL vb.net in Visual Studio 2008
You need to send the UserID and Password to the report. so it wont ask you for it when u run it. -
-
Dim report As New ReportDocument
-
Dim connection As IConnectionInfo
-
Dim oldServerName As String = ".\SQLEXPRESS"
-
Dim oldDatabaseName As String = "Old DatabaseName"
-
Dim newServerName As String = strOldServerName
-
Dim newDatabaseName As String = strCompanyName
-
Dim UserID As String = ""
-
Dim Password As String = ""
-
-
report.Load(Application.StartupPath + "\Reports\example.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()
-
|