Wednesday, March 21, 2012

How to change datasource location without having to connect to target database?

I know this is not related directly to Visual Basic, but maybe I can get some helpful feedback here.

We have developed a CR XI report using a local SQL Server database and several tables/views from it. The way we normally change the database a report uses is by going to the Change Datasource Location menu option, creating a new connection to the database and mapping both the main report and each table/view in the report to the new datasource and the new tables/views.

This is what I mean:
http://img411.imageshack.us/img411/9236/crmain8wz.jpg (general report connection properties)
http://img92.imageshack.us/img92/3397/crtable4zp.jpg (specific table/view connection properties)

We now need to distribute this report to the client and need to change the database the report uses. We have the name of the server and database at the client's site, but we obviously have no access to connect to it.

How do we change the datasource location in this case?

Thank you in advance.By the way, I tried using the code in this Microsoft page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrftableclassapplylogoninfomethodtopic.asp

The code is:

Private Sub LogonToReport (ByVal server As String, ByVal database As String, ByVal ID As String, ByVal password As String)
Dim logonInfo As New TableLogOnInfo()
Dim table As Table

' Set the logon information for each table.
For Each table In Report.Database.Tables
' Get the TableLogOnInfo object.
logonInfo = Table.LogOnInfo
' Set the server or ODBC data source name, database name,
' user ID, and password.
logonInfo.ConnectionInfo.ServerName = server
logonInfo.ConnectionInfo.DatabaseName = database
logonInfo.ConnectionInfo.UserID = ID
logonInfo.ConnectionInfo.Password = password
' Apply the connection information to the table.
Table.ApplyLogOnInfo(logonInfo)
Next table
End Sub

(Although I actually used the C# variant, but this is a VB forum.)

The second the ApplyLogOnInfo method is called, the CR component tries to connect to the database. WHY? Is there a way to avoid this?|||I have used this same code and I still have a problem
The connection details are passed using an ini file.
When developing the report (the actual rpt file) we have one database e.g. db1. When the report is copied to the production server we have another database name e.g. db2
The report rpt file holds on to the first name (db1), even though the c# code is showing the database name passed is db2.
Does anyone out there know a way to get the report to use the new database name?sql

No comments:

Post a Comment