Error when running crystal report (8.5) through VB 6 
Author Message
 Error when running crystal report (8.5) through VB 6

When I develop Crystal Reports, I can run a preview and view the
correct results without any problems.  When I bring the report into
Visual Basic, I have an error with the following message.

Run-time error '-2147192184 (80047288)':

Server has not yet been opened.

My objective is to tell my COM object to read a report from the file
system, determine where the server is to get the data from and specify
the parameters.  When this is done, I need to export that information
to a Word document.  From the following code, I get up to the area
where it states ".Export False" in the "SaveAs" subroutine.  I have
run all over the news groups and tried different variations without
any luck.  After this COM object is made, it will be used with both a
VB stand alone application for the administrator, and an ASP page for
other individuals involved with the project to download Word Documents
exported from the crystal report.

I am under the impression that this error may have to do with the fact
that I change the location of my SQL Server, the name of the database,
and the user who is logging into the database.  I have 3 different
databases here (Development, Test & Production).  Development server
has two seperate identical databases that I test with before it goes
off to the Test Server.  The only problem with this theory is that I
can not get any scenario to work no matter who the user is that is
logging into the database through Visual Basic.  It always works with
the Designer though.

Also, I havn't been able to successfully get NT User accounts
authenticated as trusted connections without asking for the
Username/password in VB - this is my primary goal for logging users
into the database.  I can grab the UserName from the API that NT
provides, but a password is impossible (imagine the security problems
if it were possible).  I was under the impression that using
"SetLoginInfo" without specifying UserName/Password would
automatically user NT Authentication of the current user for a
"trusted_connection".  Any hints out there?

--------------------------------------------------------------------------------
Option Explicit

Dim mobjApp As CRAXDRT.Application
Dim mobjReport As CRAXDRT.Report
Dim mstrDBDatabase As String
Dim mstrDBServer As String
Dim mstrDBUser As String
Dim mstrDBPassword As String
--------------------------------------------------------------------------------

Public Sub OpenReport(ByRef pstrReportSource)

    Dim lstrLocation As String
    Dim llngIndex As Long

    Set mobjReport = mobjApp.OpenReport(pstrReportSource, 1)

    With mobjReport.Database.Tables(1)

        ' Switch the location stored within the report itself
        lstrLocation = .Location
        llngIndex = InStr(1, lstrLocation, "Proc(", vbTextCompare)
        lstrLocation = mstrDBDatabase & ".dbo." & Mid(lstrLocation,
llngIndex)
        .Location = lstrLocation

        ' Set login info
        .SetLogOnInfo mstrDBServer, mstrDBDatabase, mstrDBUser,
mstrDBPassword

    End With
End Sub
--------------------------------------------------------------------------------

Public Sub SaveAs(ByRef pstrFileName As String)
    With mobjReport
        .ExportOptions.DestinationType = crEDTDiskFile
        .ExportOptions.DiskFileName = pstrFileName
        .ExportOptions.FormatType = crEFTWordForWindows
        .Export False
    End With
End Sub
--------------------------------------------------------------------------------

Public Sub SetParameter(ByRef pstrName As String, ByRef pvarValue As
Variant)
    On Error Resume Next
    If mobjReport.ParameterFields.GetItemByName(pstrName).IsCurrentValueSet
Then
        mobjReport.ParameterFields.GetItemByName(pstrName).ClearCurrentValueAndRange
    End If
    mobjReport.ParameterFields.GetItemByName(pstrName).AddCurrentValue
pvarValue
End Sub
--------------------------------------------------------------------------------

Private Sub Class_Initialize()
    Set mobjApp = New CRAXDDRT.Application
    Set mobjReport = New CRAXDRT.Report
    mstrDBDatabase = "MyDatabase"
    mstrDBServer = "MyServer"
    mstrDBUser = "MyName"
    mstrDBPassword = "MyPassword"
End Sub
--------------------------------------------------------------------------------

Private Sub Class_Terminate()
    Set mobjReport = Nothing
    Set mobjApp = Nothing
End Sub
--------------------------------------------------------------------------------



Sun, 04 Apr 2004 05:16:52 GMT  
 Error when running crystal report (8.5) through VB 6
This is a condensed version of my problem.  I have two basic
variations I have tried.  One using ADODB command and connection
objects for the data-source.

    Dim lobjCmd As ADODB.Command
    Dim lobjCon As ADODB.Connection
    Dim lobjReport As CRAXDRT.Report
    Dim lobjApp As CRAXDDRT.Application
    Dim lstrLocation As String
    Dim llngIndex As Long
    Dim lstrDBDatabase As String
    Dim lstrDBServer As String
    Dim lstrDBUser As String
    Dim lstrDBPassword As String

    lstrDBDatabase = "MyDatabase"
    lstrDBServer = "MyServer"
    lstrDBUser = "MyUser"
    lstrDBPassword = "MyPassword"

    Set lobjApp = New CRAXDRT.Application
    Set lobjReport = lobjApp.OpenReport("C:\FTR.rpt", 1)

    If 1 = 1 Then

        Set lobjCon = New ADODB.Connection
        Set lobjCmd = New ADODB.Command

        lobjCon.Open "DRIVER=SQL
Server;UID=contracts;Database=ContractsDEV;PWD=contracts;SERVER=amecs2c;"
        lobjCmd.ActiveConnection = lobjCon
        lobjCmd.CommandText = "EXEC sprReportMPR 51285, '" & Now() &
"'"
        lobjReport.Database.AddADOCommand lobjCon, lobjCmd ' this line
causes error

        Set lobjCmd = Nothing
        Set lobjCon = Nothing

    Else

        lobjApp.LogOnServer "P2SODBC.DLL", lstrDBServer,
lstrDBDatabase, lstrDBUser, lstrDBPassword ' this line causes errors
        'lobjApp.LogOnServer "PDSODBC.DLL", lstrDBServer,
lstrDBDatabase, lstrDBUser, lstrDBPassword
        lobjReport.Database.LogOnServer "PDSODBC.DLL", lstrDBServer,
lstrDBDatabase, lstrDBUser, lstrDBPassword
        lobjReport.Database.Tables(1).SetLogOnInfo lstrDBServer,
lstrDBDatabase, lstrDBUser, lstrDBPassword
        lobjReport.Database.Tables(1).SetSessionInfo lstrDBUser,
lstrDBPassword

        ' Switch the location stored within the report itself
        lstrLocation = lobjReport.Database.Tables(1).Location
        llngIndex = InStr(1, lstrLocation, "Proc(", vbTextCompare)
        lstrLocation = lstrDBDatabase & ".dbo." & Mid(lstrLocation,
llngIndex)
        lobjReport.Database.Tables(1).Location = lstrLocation

        ' Add parameters

51285

Now()

    End If

    ' Export
    lobjReport.ExportOptions.DestinationType = crEDTDiskFile
    lobjReport.ExportOptions.DiskFileName = "C:\FTR.doc"
    lobjReport.ExportOptions.FormatType = crEFTWordForWindows

    lobjReport.Export False ' This line causes error

    Set lobjApp = Nothing
    Set lobjReport = Nothing



Sun, 04 Apr 2004 22:34:22 GMT  
 Error when running crystal report (8.5) through VB 6
The problem has been solved.  

Option Explicit

Private mobjReport As CRAXDRT.Report

' Database Login information
Public Database As String
Public Server As String
Public User As String
Public Password As String

Public Sub ExportWord(ByRef pstrTarget As Variant)

    ' Export
    mobjReport.ExportOptions.DestinationType = crEDTDiskFile
    mobjReport.ExportOptions.DiskFileName = pstrTarget
    mobjReport.ExportOptions.FormatType = crEFTWordForWindows

    mobjReport.Export False

End Sub

Public Sub Export(ByRef pstrTarget As Variant, ByRef plngFormat As
CRExportFormatType)

    ' Export
    mobjReport.ExportOptions.DestinationType = crEDTDiskFile
    mobjReport.ExportOptions.DiskFileName = pstrTarget
    mobjReport.ExportOptions.FormatType = plngFormat

    mobjReport.Export False

End Sub

Public Sub LoadReport(ByRef pstrFileName As Variant)

    Dim lobjApp As CRAXDRT.Application
    Dim lstrLocation As String
    Dim llngIndex As Long

    Set lobjApp = New CRAXDRT.Application
    Set mobjReport = lobjApp.OpenReport(pstrFileName, 1)
    Set lobjApp = Nothing

    ' Switch the location stored within the report itself
    lstrLocation = mobjReport.Database.Tables(1).Location
    llngIndex = InStr(1, lstrLocation, "Proc(", vbTextCompare)
    lstrLocation = Database & ".dbo." & Mid(lstrLocation, llngIndex)
    mobjReport.Database.Tables(1).Location = lstrLocation

    ' Login to server
    mobjReport.Database.Tables(1).SetLogOnInfo Server, Database, User,
Password

End Sub

Public Property Get Report() As CRAXDRT.Report

    Set Report = mobjReport

End Property

Public Sub SetParameter(ByRef pstrName As String, ByRef pvarValue As
Variant)

    ' clear default value
    If mobjReport.ParameterFields.GetItemByName(pstrName).IsCurrentValueSet
Then
        mobjReport.ParameterFields.GetItemByName(pstrName).ClearCurrentValueAndRange
    End If

    mobjReport.ParameterFields.GetItemByName(pstrName).AddCurrentValue
pvarValue

End Sub

Private Sub Class_Initialize()

    Set mobjReport = New CRAXDRT.Report

    ' Setup default database login information
    Database = "MyDatabase"
    Server = "MyServer"
    User = "MyUser"
    Password = "MyPassword"

End Sub

Private Sub Class_Terminate()
    Set mobjReport = Nothing
End Sub



Sat, 10 Apr 2004 04:03:03 GMT  
 Error when running crystal report (8.5) through VB 6
Try functionality of exporting to RTF, and see whether your code
works.

In exporting to word what version of crxf_wordw.dll and u2fwordw.dll
do you have?

Try to download the  latest release pack for export DLLs.

name of the file:
Dbexdrvr.zip
downloaded from:
http://support.crystaldecisions.com/downloads

I know that exporting to word format crashed on me (CRPEAuto based VB
solution, user hits export button on a report, when report contained
any JPEG format images.

Alexei Akimov
tel.416-630-2095
SQL Server, VB, ASP, Crystal Reports Developer


Quote:
> The problem has been solved.  

> Option Explicit

> Private mobjReport As CRAXDRT.Report

> ' Database Login information
> Public Database As String
> Public Server As String
> Public User As String
> Public Password As String

> Public Sub ExportWord(ByRef pstrTarget As Variant)

>     ' Export
>     mobjReport.ExportOptions.DestinationType = crEDTDiskFile
>     mobjReport.ExportOptions.DiskFileName = pstrTarget
>     mobjReport.ExportOptions.FormatType = crEFTWordForWindows

>     mobjReport.Export False

> End Sub

> Public Sub Export(ByRef pstrTarget As Variant, ByRef plngFormat As
> CRExportFormatType)

>     ' Export
>     mobjReport.ExportOptions.DestinationType = crEDTDiskFile
>     mobjReport.ExportOptions.DiskFileName = pstrTarget
>     mobjReport.ExportOptions.FormatType = plngFormat

>     mobjReport.Export False

> End Sub

> Public Sub LoadReport(ByRef pstrFileName As Variant)

>     Dim lobjApp As CRAXDRT.Application
>     Dim lstrLocation As String
>     Dim llngIndex As Long

>     Set lobjApp = New CRAXDRT.Application
>     Set mobjReport = lobjApp.OpenReport(pstrFileName, 1)
>     Set lobjApp = Nothing

>     ' Switch the location stored within the report itself
>     lstrLocation = mobjReport.Database.Tables(1).Location
>     llngIndex = InStr(1, lstrLocation, "Proc(", vbTextCompare)
>     lstrLocation = Database & ".dbo." & Mid(lstrLocation, llngIndex)
>     mobjReport.Database.Tables(1).Location = lstrLocation

>     ' Login to server
>     mobjReport.Database.Tables(1).SetLogOnInfo Server, Database, User,
> Password

> End Sub

> Public Property Get Report() As CRAXDRT.Report

>     Set Report = mobjReport

> End Property

> Public Sub SetParameter(ByRef pstrName As String, ByRef pvarValue As
> Variant)

>     ' clear default value
>     If mobjReport.ParameterFields.GetItemByName(pstrName).IsCurrentValueSet
> Then
>         mobjReport.ParameterFields.GetItemByName(pstrName).ClearCurrentValueAndRange
>     End If

>     mobjReport.ParameterFields.GetItemByName(pstrName).AddCurrentValue
> pvarValue

> End Sub

> Private Sub Class_Initialize()

>     Set mobjReport = New CRAXDRT.Report

>     ' Setup default database login information
>     Database = "MyDatabase"
>     Server = "MyServer"
>     User = "MyUser"
>     Password = "MyPassword"

> End Sub

> Private Sub Class_Terminate()
>     Set mobjReport = Nothing
> End Sub



Mon, 10 May 2004 01:17:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Crystal Reports 8.5 (VB6) to Crystal Reports NET (VB.NET) conversion

2. vb .net crystal reports not compatible with Crystal Reports 8.5

3. Running Crystal 8.5 Reports on Crystal 9 RAS

4. running report in Crystal 8.5 via VB6

5. Crystal 8.5 crashes when running a report that contain subreports multiple times in a row

6. help:crystal report 8.5 error out date export dll

7. Error after upgrade to Crystal Reports 8.5

8. Crystal Report 8.5 and error when packaging the aplication

9. Crystal Reports 8.5, messagebox error to the start

10. Crystal Report 8.5 and VB .net

11. Crystal Reports 8.5 Grouping Definition in VB.

12. VB Crashes when inserting a Crystal 8.5 Report Designer

 

 
Powered by phpBB® Forum Software