Crystal Reports 8.5 and Visual Basic 6--Err Message" Server has not yet been opened"

Spider_Monkey
04-14-2004, 09:22 AM
I have been trying to get a pre-developed crystal report to display in a VB6 app at runtime. I can get the report to display with saved data, but when ever I use the .DiscardSavedData method and try to refresh the data I get an error message. The message is this "Server has not been opened". This is my first encounter with this version of Crystal 8.5, so I am sure that I am not using a certain method that is needed. Another question I had is do I even need to open an ADO recordset to populate the report?

Also, one other thing to point out is that my report is using to different tables from with in the same database.

=======================================================
'Declare GS Connection
Public cnGS As New ADODB.Connection

'Declare Connection String Variable
Public sGSConString As String

'Declare ADO record set
Public rsSelect As New ADODB.Recordset
Public rsExec As New ADODB.Recordset

'Declare SQL query string
Public sSQLSelect As String
Public sSQLExec As String

' Declare the application object
Public crxApplication As New CRAXDRT.Application

' Declare report object
Public crxReport As CRAXDRT.Report

Private Sub cmdViewReport_Click()

Call LoadReport

End Sub

Private Sub Form_Load()

Call OpenDatabase

End Sub

Public Function LoadReport()

Set crxReport = New CRAXDRT.Report
Set crxApplication = CreateObject("crystalruntime.application")

Set crxReport = crxApplication.OpenReport("C:\Report1Test.rpt", 1)

crxReport.DiscardSavedData
crxReport.Database.SetDataSource rsSelect

crvViewer.ReportSource = crxReport
crvViewer.ViewReport


End Function


Public Function OpenDatabase()

'Setup the GS database connection
Set cnGOS = New ADODB.Connection
sGSConString = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=noway;Password=nohow;Initial Catalog=GR;Data Source=GS"
cnGS.ConnectionString = sGSConString
cnGS.Open
cnGS.CursorLocation = adUseClient

sSQLSelect = "SELECT * FROM OMDR"

rsSelect.Open sSQLSelect, cnGS, adOpenDynamic, adLockReadOnly
rsSelect.MoveFirst

End Function
========================================================

Any suggestions would be appreciated!
:eek:

MKoslof
04-14-2004, 03:19 PM
Why are you doing this:

Set crxApplication = CreateObject("crystalruntime.application")

This won't work. What you want in VB is the CRAXDRT.Application, something you have already defined once in this code. Also, don't use public CRAXDRT objects, just use Dimmed variables within the scope the module.

And you never connect your report to the Database and corresponding tables. You can use your ADO connection and recordset, but you also need to use the SetLogonInfo method to pass your table information to your report at run-time. You load your report before calling your "Open Database" command, so the report has no open connection or recordsource to refer to.

Spider_Monkey
04-14-2004, 04:00 PM
MKoslof thanks for the reply, this helps get me going in the right direction. Do you have any code samples of how to connect to the databases and tables? Also, which object do I need to set the "SetLogonInfo" on. I have tried setting that before and it didn't seem to work for me.

Why are you doing this:

Set crxApplication = CreateObject("crystalruntime.application")

This won't work. What you want in VB is the CRAXDRT.Application, something you have already defined once in this code. Also, don't use public CRAXDRT objects, just use Dimmed variables within the scope the module.

And you never connect your report to the Database and corresponding tables. You can use your ADO connection and recordset, but you also need to use the SetLogonInfo method to pass your table information to your report at run-time. You load your report before calling your "Open Database" command, so the report has no open connection or recordsource to refer to.

MKoslof
04-15-2004, 07:10 AM
See below, make sure you are using the Active Data Driver for your report data base type. And you have the proper references marked in your VB project file.



Dim crxApp As CRAXDRT.Application
Dim crxReport As CRAXDRT.Report
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim crxTable As CRAXDRT.DatabaseTable
Dim sSQL, sConn as string

'instantiate all objects

Set crxApp = New CRAXDRT.Application
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set crxReport = crxApp.OpenReport("C:\fieldsTest.rpt", 1)

'do your standard SQL and ADO connection and recordset work
sSQL = "SELECT * FROM Documents WHERE DocID > 290 ORDER BY DocName DESC;"

sCon = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=noway;Password=nohow;Initial Catalog=GR;Data Source=GS"

cn.ConnectionString = sCon
cn.CursorLocation = adUseClient
cn.Open

Set rs = New ADODB.Recordset

rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText

'now loop all tables in your report object
'pass the appropriate log in info

For Each crxTable In crxReport.Database.Tables
crxTable.SetLogonInfo "serverName", "dataBase", "userName", "pw"
Next

'disgard any present data that might be saved with the report
crxReport.DiscardSavedData

'set the datasource to match the current recordset
crxReport.Database.SetDataSource rs

'print out here, or finish off your CRViewer code
crxReport.PrintOut

Spider_Monkey
04-15-2004, 02:29 PM
That worked great! Thank you for your help! This will help me to get through the next few days before my book gets in.



Dim crxTable As CRAXDRT.DatabaseTable

For Each crxTable In crxReport.Database.Tables
crxTable.SetLogonInfo "serverName", "dataBase", "userName", "pw"
Next

MKoslof
04-15-2004, 04:39 PM
No problem, good luck

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum