3
votes

I have a VB6 application that uses Crystal Reports 8.5 to view reports. I now have created a new report that uses an SQL Server stored procedure as a data source. When viewing this report in my application I use a ADODB.Recordset as a data source for the report. The problem is that Crystal Reports fails to show the report. It only shows an empty database error message, and an informational warning that the "Server has not yet been opened.".

I googled like my life depends on it but I only found examples of wokring situations that do exactly what I am doing. Sometimes with some minor differences but I tried them all. They keep ending with the same error messages.

This is my code to fill the recordset.

Dim Records As ADODB.Recordset
Dim Cmd As ADODB.Command
Set Cmd = New ADODB.Command
Cmd.ActiveConnection = clSQL.DBConnection   '< -- Existing connection that uses CursorLocation adUseClient
Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "SPCrystalReports"

Cmd.Parameters.Append Cmd.CreateParameter("ReportType", adVarChar, adParamInput, 256, Soort)
Cmd.Parameters.Append Cmd.CreateParameter("ReportFile", adVarChar, adParamInput, 256, RapportNaam)
Cmd.Parameters.Append Cmd.CreateParameter("Template", adVarChar, adParamInput, 256, Template)
Cmd.Parameters.Append Cmd.CreateParameter("WhereClause", adVarChar, adParamInput, 8000, CentralSQL)
Cmd.Parameters.Append Cmd.CreateParameter("WhereClause2", adVarChar, adParamInput, 8000, ExtraSQL)
Cmd.Parameters.Append Cmd.CreateParameter("Date", adDate, adParamInput, , Datum)
Cmd.Parameters.Append Cmd.CreateParameter("DateFrom", adDate, adParamInput, , DatumVan)
Cmd.Parameters.Append Cmd.CreateParameter("DateTo", adDate, adParamInput, , DatumTot)

Set Records = Cmd.Execute

Set Cmd = Nothing

This is how I load my report:

Dim crApp As CRAXDRT.Application
Dim crRep As CRAXDRT.Report

Set crApp = New CRAXDRT.Application
Set crRep = crApp.OpenReport(ReportFile, 1)

And then I tried the folowing code samples to get the report working.

Sample 1:

crRep.DiscardSavedData
crRep.Database.SetDataSource Records

Sample 2:

crRep.DiscardSavedData
crRep.Database.SetDataSource Records, 3, 1

Sample 3:

crRep.Database.Tables(1).SetLogOnInfo DBServer, DBDatabase, DBUser, DBPass
crRep.DiscardSavedData
crRep.Database.SetDataSource Records, 3, 1

Sample 4:

crRep.DiscardSavedData
crRep.Database.Tables(1).SetDataSource Records, 3

Sample 5:

crRep.Database.Tables(1).SetLogOnInfo DBServer, DBDatabase, DBUser, DBPass
crRep.DiscardSavedData
crRep.Database.Tables(1).SetDataSource Records, 3

Sample 6:

crRep.DiscardSavedData
crRep.Database.Tables(1).SetPrivateData 3, Records

Sample 7:

crRep.Database.Tables(1).SetLogOnInfo DBServer, DBDatabase, DBUser, DBPass
crRep.DiscardSavedData
crRep.Database.Tables(1).SetPrivateData 3, Records

They all end up with this error popup followed by the information popup.

Empty error message Information popup

How to get this working?

1
Tag your question with sql-server for it to receive more eye-balls from the much bigger DB sub-community.wqw

1 Answers

0
votes

If there is no execution error and Records variable contains data, try with (Object Browser invisible) method SetPrivateData:

crRep.Database.Tables(1).SetPrivateData 3, Records

Pdsoledb.dll (p2soledb.dll) as crRep.Database.Tables(1).DllName indicates that your report should retrieve data from a database by itself, so try something like this:

With crRep.Database.Tables(1).ConnectionProperties
    .DeleteAll
    .Add "Connection String", " insert a connection string here "
End With

or use LogOnServer method like here VB and Crystal Reports problem

or change report's connection type to Field Definitions Only.