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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation Error in CR9.0 1

Status
Not open for further replies.

MichaelaLee

Programmer
May 3, 2004
71
US
Hi All,
I have a major problem with Crystal Reports I'm hoping someone can help. I'm using VB6, ADO 2.7 and CR9.0. I have a simple report that everytime on the second run of the report (without restarting app) I get the following error message:
Error Number: 2147417848
Automation Error, The object invoked has disconnected from its client.

Here is the code it happens on:
Dim rs As New ADODB.RecordSet
Dim crxDBTables As CRAXDRT.DatabaseTable
Dim crxReport As CRAXDRT.Report
Set rs = SetReportData(ProgramId, OrderId)
Set crxReport = crInvoice
Set crxDBTables = crxReport.Database.Tables(1)
For Each crxDBTables In crxReport.Database.Tables
If crxDBTables.ConnectionProperties("Data Source") <> gDbPath Then
crxDBTables.ConnectionProperties("Data Source") = gDbPath
crxDBTables.ConnectionProperties("User Id") = "Admin"
crxDBTables.ConnectionProperties("Provider") = "Microsoft.Jet.OLEDB.4.0"
End If
Next
crxReport.Database.SetDataSource rs
CRViewer91.ReportSource = crxReport

It seems to happen the second time through as I said before, and it seems that the line crxDBTables.ConnectionProperties("Data Source") is causing the error. If I break at that point and hold my mouse over the code VB crashes with the following error:
Microsoft Visual C++ Runtime Library
Program VB6.exe
This app has requested the runtime to terminate it in an unusual way.
Please help. Has anyone had this problem. Thanks for any help.
Michael Lee


 
If you're going to send a recordset as the data source, then you don't need to set the ConnectionProperties - just send the recordset:
[tt]
Dim rs As New ADODB.RecordSet
Dim crxReport As CRAXDRT.Report
Set rs = SetReportData(ProgramId, OrderId)
Set crxReport = crInvoice
crxReport.DiscardSavedData
crxReport.Database.SetDataSource rs
CRViewer91.ReportSource = crxReport
CRViewer91.ViewReport
[/tt]

You're not getting errors the first time you run the report because the report was created with an OLEDB Access connection, which matches the ConnectionProperties you're setting. The recordset you're creating and sending to the report probably has the same structure as the SQL statement that the original report generated. As soon as you call the SetDataSource method and send the recordset as the report's data source, it must be altering the ConnectionProperties - thus the reason why it fails when you try to call the report a second time.

You could probably get by with your current code if you had a [tt]Set crxReport = Nothing[/tt] call after you're finished viewing the report.

-dave
 
Hi vidru,
Thank you so much for your input. That took care of the problem. Thanks again.
Michael Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top