Ok, outside the development environment, it's hanging up on either ApplyLogOnInfo or the Location setting. Function ExtractServerDatabaseNames is returning the correct Server and Database names. Below is my code used for modifying the Server/Databasename and I use Stored Procedures for the CrystalReportViewer data. Anyone have a suggestion?
Public Sub SetDatabaseLogonConnection(ByRef MyReport As Object, ByVal MyConnectionString As String)
'During runtime, the Production server/database needs to be updated from the development server/database.
'The purpose of this sub is to dynamically update the server/database at runtime.
Dim MyServerName As String = String.Empty
Dim MyDatabaseName As String = String.Empty
Dim MyTable As CrystalDecisions.CrystalReports.Engine.Table
Dim MyConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
Dim MyLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
'Get the Server and Databasename from the project connection string
If ExtractServerDatabaseNames(MyConnectionString, MyServerName, MyDatabaseName) Then
'Update the Server/Databasename in the report
For Each MyTable In MyReport.Database.Tables
MyLogonInfo = MyTable.LogOnInfo
'We need the userid/password from MyConnectionInfo initialized before modifying the Server/Databasename
MyLogonInfo.ConnectionInfo = MyConnectionInfo
'Reset the target Server and Database names
If MyServerName <> String.Empty Then
'If you have a need for a Secure Datasource, you would need to update the userid/password here
'BEFORE calling ApplyLogOnInfo
MyLogonInfo.ConnectionInfo.ServerName = MyServerName
MyLogonInfo.ConnectionInfo.DatabaseName = MyDatabaseName
MyLogonInfo.ConnectionInfo.IntegratedSecurity = True
End If
MDIParent1.ToolStripStatusLabel.Text = "Applying Crystal Reports connection to database " & MyServerName & "/" & MyDatabaseName & "...Please wait"
MDIParent1.Update()
MyTable.ApplyLogOnInfo(MyLogonInfo)
If MyServerName <> String.Empty Then
MyTable.Location = MyTable.Location.Substring(MyTable.Location.LastIndexOf(".") + 1)
End If
Next
End If
End Sub
Public Function ExtractServerDatabaseNames(ByVal MyConnectionString As String, ByRef MyServerName As String, ByRef MyDatabaseName As String) As Boolean
'Extract the Server/Databasename from the project connection string
Const DataSource As String = "Data Source="
Const InitialCatalog As String = "Initial Catalog="
Dim Results() As String
Try
Results = Regex.Split(MyConnectionString, ";", RegexOptions.Multiline)
Catch exp As Exception
MsgBox("An error was encountered when attempting to parse the Connection String. Check to insure that the connection exists." & vbCrLf & exp.Message, _
MsgBoxStyle.Critical, Me.Text)
Return False
End Try
' To be split a string array of at least two elements must be created.
If Results.Length > 1 Then
For Each s As String In Results
If InStr(1, s, DataSource) Then
MyServerName = Trim(Mid(s, Len(DataSource) + 1, Len(s) - Len(DataSource)))
ElseIf InStr(1, s, InitialCatalog) Then
MyDatabaseName = Trim(Mid(s, Len(InitialCatalog) + 1, Len(s) - Len(InitialCatalog)))
End If
Next
End If
Return True
End Function
Edited by VBProEd - 22 Apr 2008 at 8:45am