Link to home
Start Free TrialLog in
Avatar of miuku
miuku

asked on

Password protected Access database and Crystal Report

Hi,
I have problems with connecting MS Access 2000 database protected with password. I have tried to get help with this article: http://support.businessobjects.com/library/kbase/articles/c2010371.asp but could not get it work...

I have selected OLE DB connection from Desing window and created report without Database password.

Here is my code (I have used that article when creating it):  
The code works fine without password. When I'm settin password and running report, I get window "Database login" and it always says "logon failed".  If I try to connect database in Desing window, I get error: "Login Failed. Cannot start your application, the workgroup file is either missing or opened exclusively by another user."

Database location have to change when running, and I store right location from textfile.
I am using .NET 2003 and Crystal Report that came with.

And my code:
********
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     'Help from here: http://support.businessobjects.com/library/kbase/articles/c2010371.asp

        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table

        Dim crReportDocument As New CrystalReport1

        'getting database location (like c:\myDatabase.mdb)
        'Location is different than what is set in Design window
        Dim sr As New System.IO.StreamReader("datab.txt")
        Dim MyDatabase As String = sr.ReadLine()
        sr.Close()

        'Set the ConnectionInfo properties for logging on to
        'the Database
        With crConnectionInfo
            .ServerName = MyDatabase
            .UserID = "Admin"
            .Password = "MyPassword"
        End With

        ' Set the CrTables to the Tables collection of the report
        CrTables = crReportDocument.Database.Tables

        'Loop through each table in the report and apply the
        'LogonInfo information

        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next

        'Set the viewer to the report object to be previewed.
        CrystalReportViewer1.ReportSource = crReportDocument
    End Sub
********

Hope that someone can help me,
-M-
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of miuku
miuku

ASKER

Thanks but it didn't help...

In .NET version of CR is no 'OLE BD' selection in 'More Data Sources'. Then I selected Access/Excel (DAO)  but there is no 'Data Link Properties' dialog box. I still get database working in Design window, but if I try to run report, i get same "Database login" window and it says that logon failed.

***Here is the code now:***      

       'Open an instance of the report in memory
        Dim CrTables As Tables
        Dim CrTable As Table
        Dim CrReport As New CrystalReport2

        CrTables = CrReport.Database.Tables

        'getting database location (like c:\myDatabase.mdb)
        'Location is different than what is set in Design window
        Dim sr As New System.IO.StreamReader("datab.txt")
        Dim MyDatabase As String = sr.ReadLine()
        sr.Close()

        'Loop through the tables collection and set the location of the access database for
        'each table.
        For Each CrTable In CrTables
            CrTable.Location =MyDatabase
        Next

        ' Set the report object as the report source for the viewer
        CrystalReportViewer1.ReportSource = CrReport

*******
Are you using the standard mdw file?

look at
http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp

Use the logon subreport sample

mlmcc
Avatar of miuku

ASKER

I worked out this problem. It works fine with Access/Excel (DAO) -connection if I use that first code. And don't ask why I changed code when trying peter57r's link.... =)