Crystal Report Viewer error ?

In Vb I run the following code with no errors but when I run the code
it gives me the error dialog box "Server has not yet been Opened" on
the CR Viewer.
How do I fix this?

   
Set Report = CrystalRPT.OpenReport("c:/temp/crystalreports/xyz.rpt")
Report.DiscardSavedData

Report.RecordSelectionFormula = "{x}=0"

CRViewer1.ReportSource = Report
'CRViewer1.Refresh

CRViewer1.ViewReport

 
7of9121098Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AzraSoundCommented:
I encountered this problem before as well and finally just initiated the connection to the database myself, e.g.,

Set Report = CrystalRPT.OpenReport("c:/temp/crystalreports/xyz.rpt")
Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"
Report.DiscardSavedData
etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlmccCommented:
What database and how are you connecting.  I think Azra is on the correct track.

mlmcc
0
FicusCommented:
You made your .rpt file in the CR IDE and now are opeing it in VB?

If you open a .rpt file that has data saved with it (does yours?) the report tries to connect to the data source that was used when you created the report.  I had that message before and I think it was the order of the statments.

I love the results of ccrystal reports but had a hard time pinning down all the syntax.

here is a paste from a project that used .rpt files, set their datasource at run time and dynamicaly created the reports.  VB6 SP5, CR8.5, Access DB, No report designer in project - Maybe that will help.  Good luck.

Private Sub L_SpawnCRView()
  Dim i As Integer, j As Integer
  Dim LInt_RepCount As Integer
  Dim CRXReport As CRAXDRT.Report
  Dim ff
 
  'On Error GoTo errhandle
   
  If hfg_reports.Rows = 0 Then Exit Sub
 
  Screen.MousePointer = vbHourglass
 
  'Create a new child viewer form - Find free index or increase array
  LInt_RepCount = GF_CRV_Form_New()
 
  'tag and caption for new viewer child form
  CRV_Form(LInt_RepCount).Caption = "Reporte #" & LInt_RepCount & " - " & hfg_reports.TextMatrix(hfg_reports.Row, 1)
 
  'Open our report template (*.rpt) and assign it to our Local report Object (file name based off label.caption)
  Set CRXReport = CRXApplication.OpenReport(GStr_ReportsPath & lbl_reportfilename.Caption)
       
   
  'Bind to current data
  Dim DBTable
  For Each DBTable In CRXReport.Database.Tables
    DBTable.Location = GStr_RootDataPath & GCStr_DBName_MergedPOS
  Next
  CRXReport.ReadRecords
 
  'assign report to Type CRV_FormState (we manipulate this to change scope in viewing)
  Set CRV_FormState(LInt_RepCount).ReportObject = CRXReport
   
  'Set attributes and default scope for this report (eg. tpye = 'otro' (needs to be there regardless of date scope we add later...)
  CRV_FormState(LInt_RepCount).ReportStyle = Val(hfg_reports.TextMatrix(hfg_reports.Row, 3))
  CRV_FormState(LInt_RepCount).DefaultFormula = CRV_FormState(LInt_RepCount).ReportObject.RecordSelectionFormula
 
  'OLD METHOD (FIELD STILL IN DB)
  'CRV_FormState(LInt_RepCount).DefaultFormula = hfg_reports.TextMatrix(hfg_reports.Row, 6)
   
  'Assign report source to our report viewer
  CRV_Form(LInt_RepCount).CRViewer.ReportSource = CRV_FormState(LInt_RepCount).ReportObject
 
  'place sub-title
  For Each ff In CRV_FormState(LInt_RepCount).ReportObject.FormulaFields
    If ff.Name = "{@Title}" Then
      ff.Text = Chr$(34) & CRV_FormState(LInt_RepCount).DefaultFormula & Chr$(34)
    End If
  Next
 
 
  'View the report
  CRV_Form(LInt_RepCount).CRViewer.ViewReport
 
  Do While CRV_Form(LInt_RepCount).CRViewer.IsBusy = True
    DoEvents
  Loop
 
 
  '/ Depending on the attributes of this report display the apropriate controls on the form
  If CRV_FormState(LInt_RepCount).ReportStyle > 0 Then
    CRV_Form(LInt_RepCount).chk_alldates.Visible = True
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.Visible = True
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.ListIndex = 1
    CRV_Form(LInt_RepCount).lbl_period.Visible = True
    'TO DO: Set DTPs to High and Low Ranges of availabe Records
    '       (not the stupid default value of the date when control was placed on form
   Else
    CRV_Form(LInt_RepCount).chk_alldates.Visible = False
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.Visible = False
    CRV_Form(LInt_RepCount).lbl_period.Visible = False
  End If

 
  Screen.MousePointer = vbDefault
     
  Set CRXReport = Nothing
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

7of9121098Author Commented:
The following still gave me the same message..."Server has not yet been Opened" but no compiler errors, just at run time.

Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

 I'm using SQL Server 7 as the database.
0
AzraSoundCommented:
On which line are you getting the error?  Does it get through the above line?
0
7of9121098Author Commented:
Yes it goes through the above line...error appears at this code...
Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

Like it doesn't like it...the server and db etc is correct....
0
FicusCommented:
Try passing the arguments as double quotes (empty strings) to use the default reports settings.  Maybe you can find the part that is not liked.

Or you could try LogOnServerEx

Sub LogOnServerEx (pDllName As String, pServerName As String,
[pDatabaseName], [pUserID], [pPassword],
[pServerType], [pConnectionString])
0
FicusCommented:
70f9,
Some other ideas...

Make sure the data you are connecting to is identical to the data your report was created with.  ie. no extra fields.

Also you could try someting like in my code where you assign the table.
----------------------------------------------------------------------------------------------------
There is a white papper on the subject at
   http://support.crystaldecisions.com/communityCS/TechnicalPapers/cr_server_not_yet_been_opened.pdf

Promisingly entitled "Crystal Reports ASP Reporting - Troubleshooting: 'Server Has Not Yet Been Opened' "

Im too tired to read it but it looks very thurogh.



0
7of9121098Author Commented:
Thanks guys Its working now...the code below was correct....but

Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

  Wierd if I use the ServerName that is displayed in SQL Server or on the Network it gives me the error message "Server has not been...". But the Crystal Report uses the ODBC DSN for the ServerName under the "set location" button in Crystal Reports. So what I did as suggested in the article is to make sure the Servername matches with the CR with the VB code listed above.
  http://support.crystaldecisions.com/communityCS/TechnicalPapers/cr_server_not_yet_been_opened.pdf

P.S. I was I can give you credit to Ficus for the article and all of you guys but unfortuately I can't.

0
FicusCommented:
You can split the points but no biggy.  Glad it worked for you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.