on 04-02-2009 8:27 PM
I have been looking at several issues posted in the last few months that deal with changing the database connection information at runtime. However, none of them that I have found or read have provided the solution. I have tried a couple ways and have not been successful. I am able to get a report that has no parameters to run but a report with dynamic parameters still prompts for the database login.
Here is my code for changing the connection information.
Try
Dim myTables As Tables = myReportDocument.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
'This code is needed if you are not logged on as the owner of the database objects
'myTable.Location = "REPORTS." + myTable.Location
Next
For Each mySubRpt As ReportDocument In myReportDocument.Subreports
Dim mySubTables As Tables = mySubRpt.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In mySubTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
Next
Catch ex As Exception
MessageBox.Show("Failed to Set Database connection information : " & ex.Message, "Database Login", MessageBoxButtons.OK)
End Try
Here is the fist code that I had that would run the report and parameter screen but still pointed to the wrong datasource.
Dim myconn As New ConnectionInfo
Dim myTables As New TableLogOnInfos
myTables = RptViewer.LogOnInfo
With myconn
For i As Integer = 0 To sArr.Length - 1
If sArr(i).Contains("Data Source") Then
.DatabaseName = sArr(i).Substring(InStr(sArr(i), "="))
.ServerName = sArr(i).Substring(InStr(sArr(i), "="))
End If
If sArr(i).Contains("User") Then
.UserID = sArr(i).Substring(InStr(sArr(i), "="))
End If
'If sArr(i).Contains("Password") Then
' .Password = sArr(i).Substring(InStr(sArr(i), "="))
'End If
Next i
.Password = "password"
End With
SetDBLogonForReport(myconn, myReport)
For Each tbl As TableLogOnInfo In myTables
tbl.ConnectionInfo = myconn
Next
Any solutions?
I've see the other post you have on a similar issue. I am not sure what the solution is, but it occurs to me that this may be an issue better solved over the phone. Phone support contract can be obtained here:
Other than that, perhaps somebody else will be able to help here...
Ludek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.