Change Report Connection at Runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Changing connection info at run time with Crystal does not seem to work as
advertised. I've tried the code in the documentation and the code that's been
posted in the crystal group numerous times by Shariq. Here are my particulars:

..NET 1.1, SP1
Crystal Dev. 10
SQL Server
Report has one table (a command), and no subreports.

As long as I pass in a server name of "(local)", it works fine, no login
popup. Substituting any other value, including the local machine name or
"localhost" pops the login dialog. Even though correct credentials are
entered, it doesn't accept them. Oddly, the server and database fields are
grayed out and blank. I have verified in the debugger that the parameters are
being changed in the ConnectionInfo object. I also notice that there's an
undocumented member, ConnectionInfo.AllowCustomConnection, but toggling it
did not affect the outcome. I'm stumped. Seems like a lot of other people
are too. Thx.

--
Public Sub RunReport(ByVal myReport As ReportDocument)
Dim ReportViewer As ReportViewerForm

Dim myConnectionInfo As New ConnectionInfo
Dim myLogonInfo As New TableLogOnInfo
'myConnectionInfo.AllowCustomConnection() = True
myConnectionInfo.ServerName = "myServerName"
myConnectionInfo.DatabaseName = "myDatabaseName"
myConnectionInfo.UserID = "myUserId"
myConnectionInfo.Password = "myPassword"
For Each myTable As Table In myReport.Database.Tables
myLogonInfo = myTable.LogOnInfo
myLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myLogonInfo)
Next
....
--
 
Armin Zingler said:
Have you already had a look at the manufacturer's KB or the forums here?
http://support.businessobjects.com/programs/crystal_dev.asp

I've scoured the knowledge base and newsgroups here. Essentially the same
sample code is posted everywhere I've found anything, but that code does not
work. The details of how it doesn't work are in the original post. I've also
noticed the same question asked a few times, but not answered. Seems like a
pretty basic showstopper not to be able to do this, so I have to figure that
there is another step that is missing from the documentation. Hopefully
someone else here has used the product in a real environment and has figured
out how to do this.

I've also checked the Business Objects site, but we all know how generally
futile that is. ;-) They have another version of the code that apparently
replaces each table instead of just updating its connection. Be trying that
next.
 
Ok, some further information. This problem only seems to happen if the
"table" in quesiton is a command. As long as it's an actual table, no
problem. Can anyone shed any light on this? Thx.
 
Hello pearsons_11114,

Here is how I do it:

Dim CnInfo As New CrystalDecisions.Shared.ConnectionInfo
CnInfo.DatabaseName = "mydatabase"
CnInfo.Password = "mypassword"
CnInfo.ServerName = "myserver"
CnInfo.UserID = "myuser"

For Each entry As TableLogOnInfo In crpViewer.LogOnInfo
entry.ConnectionInfo = CnInfo
Next


Rather than creating new TableLogOnInfo object, I'm just modifying the existing
ones. Hope this helps.
 
What's crpViewer? You don't define it in the code. I tried using the
ReportViewer, but it doesn't have that member. Your code make it seem like
there is one object that holds all the LogOnInfo objects, but AFAIK they only
exist in each table. Thanks for any clarification.

Also do you find that this works when the table is actually a command? In my
testing, that's where the problem is.
 
Back
Top