Crystal 10-Change the report default server & DB connection in programming
Dear All,
I have few crystal 10 reports with default connection to a server & database during report design (server=SRV1, DB=Pub1). And, i calling these report from VB. net2003 application with a config.ini define my destination server & DB .
Recently,i hv clone the same reports but extract data from different server & Database name (Server=Srv2,DB=Pub2, the tables & fields are still same )
i have created a config.ini which contain my new destinantion server, database, uid & pwd.
BUT, when i execute these cloned report , they still extract data from old server which was server=SRV1, DB=Pub1. PLEASE HELP !!!
My coding :-
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Cursor.Current = Cursors.WaitCursor
Dim strReportName As String
Dim strConfigPath As String
strConfigPath = Application.StartupPath & "\" & "config.ini"
Dim MyDB As String = SearchValue(strConfigPath, "database")
Dim MyUID As String = SearchValue(strConfigPath, "uid")
Dim MyPWR As String = SearchValue(strConfigPath, "pwd")
Dim MySRV As String = SearchValue(strConfigPath, "server")
Dim strReportPath As String = Application.StartupPath & "\" & Trim(Me.Tag) '"\" & strReportName & ".rpt"
Dim rptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
If System.IO.File.Exists(strReportPath) = True Then
'file exists
Else
MessageBox.Show("Report File Not Exist-" & strReportPath)
Exit Sub
End If
Dim crTableLogoninfos As New TableLogOnInfos
Dim crTableLogOnInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As Tables
Dim crTable As Table
Dim TableCounter
Dim crRptDocument As New ReportDocument
crRptDocument.Load(strReportPath)
With crConnectionInfo
.ServerName = MySRV
.DatabaseName = MyDB
.UserID = MyUID
.Password = MyPWR
End With
crTables = crRptDocument.Database.Tables
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
rptViewer.ShowRefreshButton = False
rptViewer.ShowCloseButton = False
rptViewer.ShowGroupTreeButton = False
rptViewer.ReportSource = crRptDocument
Me.Cursor.Current = Cursors.Default
End Sub
Thanks in advance.
Rgds,
Jas