PDA

Click to See Complete Forum and Search --> : Change Database in Rpt using RDC


Rohan_Powle
Feb 19th, 2003, 11:07 PM
Initially I have developed the rpt using Exports DB but want to change it to Exports1. I am using Vb6, Sql Server 7 & CR8 with RDC.

I Tried the below code but was not opening Exports1 DB but showing Exports DB's data :(. But When I added this line of code (Report.SQLQueryString = "Select * From Customer") as there is only 1 table in the dummy report,
Between code Report.DiscardSavedData and Report.Database.LogOnServer the report is displayed with Exports1 DB. I am getting what I want but do I have to write the SQLQueryString for all the reports I want to change the Database? Pls let me know a feasible solution..

When I Unload the Form which has (Report.SQLQueryString = "Select * From Customer") code. VB terminates itself. One more disaster for in the way.

Pls Help me out :(


Private Sub Form_Load()
' Declare a DatabaseTable Object
Dim crxDatabaseTable As CRAXDRT.DatabaseTable

' Declare a Report object to set to the subeport
Dim crxSubreport As CRAXDRT.Report

' Open the report
Set Report = crxApplication.OpenReport("f:\rdc\cust.rpt", 1)


Report.DiscardSavedData
Report.Database.LogOnServer "pdssql.dll", "Rohan", "Exports1", "sa"

'Use a For Each loop to change the location of each
'DatabaseTable in the Reports DatabaseTable Collection
For Each crxDatabaseTable In Report.Database.Tables
crxDatabaseTable.SetLogOnInfo "Rohan", "Exports1", "sa"
Next crxDatabaseTable

End Sub

brucevde
Feb 20th, 2003, 01:07 AM
Sometimes its not enough to just change the database login. The Location of the report needs to be changed as well. By default Crystal Reports will set the location to something like Exports.Tablename (may not be exact syntax).

Two ways to solve this problem. In the Report designer change the location to just the table name. I don't have Crystal readily at hand but if I recall correctly its through the Database -> Set Location menu.

or

Using the CRAXDRT.Table object set the Location property manually in code.

Although it does not apply in your case you need to do this for every sub-report as well.