Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change datasource at runtime if the crystal report is in ADO 1

Status
Not open for further replies.

143Aroul

Programmer
Jul 17, 2003
16
FJ
Hi,

I create a report (crystal report 8.5 ) using ADO (OLEDB).
while doing it it is asking the path of the database.
say c:\Pay\payroll.mdb and it works fine.

if i rename the directory Pay to Pay1 and run the same program, says crystal report c:\pay\payroll.mdb path is not found.

can anyone help me out

 
In the Designer menu: Database...Set Location...Change the database file path in "File:" textbox from
MyTable!c:\pay\payroll.mdb
to
MyTable!c:\pay1\payroll.mdb
 
u want me to change the database path everytime, especially when i deploy my software, i don't know which path user will install.

So runtime, i want to change it, i hope u will understand
 
If you're not using external code (such as VB), then the only solution that comes to mind is to use a Universal Data Link (UDL) file.

Then you can change the UDL based on the new users install.

Note that Crystal by itself isn't designed to be portable across other systems, generally an application is involved, and you can then control and change settings.

-k
 
You should've probably mention in your first post that you are calling your report from an external application and also specify what application it is (i.e. ASP, VB, etc.). Go to Seagate site at they have a bunch of samples on how to change report data source at a run time.
 
from visual basic i am calling this report
 
Howdy all I went there and read those examples and they are great, but what I am looking for is a command line parameter to pass to the report and change the path. I find nothing in the CR documentaion. Anyone ever done that before?

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
I'm in the same boat here. But let me say it like this. I'm using an ADO OLEDB connection to an Access200 database. Now can't the report always look for the database in the same directory that the application is in. For Example in VB6 I connect to the database using "app.path" and no matter where they install it, the application finds the Database file. But how can I do that with my embedded Crystal Report?
 
First, please clarify a few things:

1) Are you in control of the vb code?
2) What version of Crystal are you using?
3) When you say embedded CRs, do you mean that you are using CRAXDDRT.DLL (i.e., the Designer and Runtime Library, as opposed to CRAXDRT, the Runtime library)? Or do you simply mean that the report is a part of your application, and the rpt files reside in your App directory?

If you are using an OLEDB connection and an external rpt file, you should be able to go into Crystal Reports and choose Database | Set Location, select the table and remove the reference to the file path, just leaving the mdb file name as the setting. Once you save the report it should look for the mdb database in the same directory as the report. If it can't find it at runtime, the logon will fail and you will get an error message (in CR, it will ask for logon info, but in VB it just fails).

But is that really what you want to do?
 
Ok, let me clarify,
I'm in control of the VB6 code.
The VB6 Application has an ADO connection string for the VB forms.
That string always uses the app.path to find the database.
This is an application installed from a CD, so it could be installed anywhere or moved anywhere as long as the VB App is in the same folder as the .mdb it will work.
I want my "CRAXDRT.dll" to do the same.
What I'm doing is creating the Report in Crystal Enterprise as a .rpt file. then within VB I choose Add CR9, and create a .dsr within a form. All works fine, the 3 week investigation of the necessary .dlls this app needs is now working. the MDAC and DCOM98 are conditionally installed silently. All is underway except Crystal ADO connection string alowing me to use a constant lke "app.path" or "CurDir" to find the .mdb file.

Any help or coments on any item I mentioned here would be appreciated.
 
So, when you create the dsr, you're using the existing report you created in CE, correct?

If so, here is a set of code, all related to a single form that contains the crystal viewer, that gets an instance of a dsr report and then resets the LogonServerName property of that report to the current app path and specific mdb file used by the report:

Option Explicit

Dim Report As New CrystalReport1
Const cMDBFileName As String = "xtreme.mdb"


Private Sub Form_Load()

Dim crTable As CRAXDRT.DatabaseTable

Set crTable = Report.Database.Tables.Item(1)
crTable.SetLogOnInfo App.Path & "\" & cMDBFileName

'For Each crTable In Report.Database.Tables
' Debug.Print crTable.Name
' Debug.Print "original server location: " & crTable.LogOnServerName
' crTable.SetLogOnInfo App.Path & "\" & cMDBFileName
' Debug.Print "new server location: " & crTable.LogOnServerName
'Next


Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
Me.WindowState = 2

End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth

End Sub

-----------------------------------

You'll notice that originally I looped through each table and did the SetLogonInfo method, but then discovered that using this method on the first table automatically updated all the tables.

The original report was designed against an Access mdb located in a different directory. That was then deleted and a copy placed in the vb app's directory. I then brought the report into the app by creating a dsr using the report as the basis. If I have understood your problem properly, this models it pretty closely. If not, let me know what I've missed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top