Article ID 2176
Article Title ERROR: "Logon Failed" using Crystal RDC
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2176
KBase Category Crystal Reports
Date Created 09/30/2005
Last Edit Date 09/29/2006


Article Text
PROBLEM:
I am trying to run a report that uses SQL Server tables through the procedure below using the cCrystal class (RDC):

Procedure OnInitializeReport handle hoReport
    Integer eDestination
    Handle hoDatabase

    Forward Send OnInitializeReport hoReport

    Get DatabaseObject of hoReport to hoDatabase
    If (hoDatabase) Begin
        Send ComLogOnServer of hoDatabase "crdb_ado.dll" "MySQLServer" "myDatabase" "myUserID" "myPassword"
    End

    // Set the print destination.
    Get PrintDestination of oDestinationGroup To eDestination
    Set peOutputDestination To eDestination

End_Procedure // OnInitializeReport

Whenever I try, the following error is displayed:

COM object method invocation error, Logon failed.
Details: ADO Error Code: 0x80004005
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC Driver Manager]Datasource name not found and no default driver specified"

What do I need to do to run the report?

SOLUTION:
You need to set the password before the report can be run (see KBase 2173 -- http://www.dataaccess.com/KBPrint.asp?ArticleID=2173). The password is the only information about the datasource that is not saved in the reports; server, database, table and user are.

So, in order to avoid the "Logon failed" error, you should do something like the following:

Function SetPassword Handle hoDatabaseTable String sPassword Returns Boolean
    Handle hoConnectionProperties hoConnectionProperty
    Variant vConnectionProperties vPasswordProperty
    Boolean bAttached bOK
    
    Move False to bOK

    Get create U_cCrystalConnectionProperties to hoConnectionProperties
    Get ComConnectionProperties of hoDatabaseTable to vConnectionProperties
    Set pvComObject of hoConnectionProperties to vConnectionProperties
    Get IsComObjectCreated of hoConnectionProperties to bAttached
    If (bAttached) Begin
        Get create U_cCrystalConnectionProperty to hoConnectionProperty
        Get ComItem of hoConnectionProperties "Password" to vPasswordProperty
        Set pvComObject of hoConnectionProperty to vPasswordProperty
        Get IsComObjectCreated of hoConnectionProperty to bAttached
        If (bAttached) Begin
            // Set the password
            Set ComValue of hoConnectionProperty to sPassword
            Move True to bOK
        End
        Send Destroy of hoConnectionProperty        
    End
    Send Destroy of hoConnectionProperties
            
    Function_Return bOK
End_Function



And the OnInitializeReport would be something like:

Procedure OnInitializeReport handle hoReport
    Integer eDestination
    Handle[] hoTables
    Handle hoDatabaseTable hoDatabase
    Integer iTableItem iTableCount
    Boolean bOK

    Forward Send OnInitializeReport hoReport

    Get DatabaseObject of hoReport to hoDatabase
    If (hoDatabase) Begin
        Get TableObjects of hoDatabase to hoTables
Move (SizeOfArray(hoTables)) to iTableCount
For iTableItem From 0 to (iTableCount -1)
           Move hoTables[iTableItem] to hoDatabaseTable
    If (hoDatabaseTable) Begin
                // set the same password for all the tables in the ADO datasource
             Get SetPassword hoDatabaseTable "myPassword" to bOK
            End
        Loop
    End

    // Set the print destination.
    Get PrintDestination of oDestinationGroup To eDestination
    Set peOutputDestination To eDestination
End_Procedure // OnInitializeReport

If the same connection information should be used for all the tables in the report, you only need to set password once; so just replace
    Move (SizeOfArray(hoTables)) to iTableCount
    For iTableItem From 0 to (iTableCount -1)
        Move hoTables[iTableItem] to hoDatabaseTable
    Loop
With
    Move hoTables[0] to hoDatabaseTable

After that, you should be able to run your report.


Contributed By:
Marcia Booth
Company: Data Access Worldwide
Web Site: http://www.dataaccess.com

Links Related to this Article
DAW Knowledge Base article 2173: INFO: LogOnServer needs password set using PESetNthTableLogOnInfo
DAW Knowledge Base article 2178: EXAMPLE: cCrystal Subclass to handle ADO Properties

Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2024 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.