Skip to Content
0
Former Member
Apr 16, 2012 at 09:07 PM

Issue with dynamic data source in VB.Net 2005

37 Views

On my dev pc I have set up several Crystal Reports against a dev MS SQL Express server (let's call it ServerA) using Database Type OLE DB (ADO) with a provider of SQLODEDB. I run into issues when trying to programmatically connect to a different MS SQL Express server (let's call it ServerB).

1) Dim rptToView As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

2) rptToView.Load(Application.StartupPath & "\" & ReportName)

3) For i As Integer = 0 To rptToView.DataSourceConnections.Count - 1

4) rptToView.DataSourceConnections.Item(i).SetConnection(ServerName, DatabaseName, UserID, Password)

5) Next

If both databases are up and running the code will load the report and then setconnection to ServerB very quickly. However, If ServerA is turned off then the .load command (line 2 in the code above) takes forever before finally progressing to the setconnection command. Clearly the report, which was created against ServerA, is trying to connect to ServerA and timing out before even giving me a chance to redirect it to ServerB. This application will be distributed to a number of different locations with different databases.

I need a way of preventing the report from automatically trying to connect to the development server before I can programmatically redirect it to the production server.

Thanks in advance