Password protected Access database and Crystal Report

Posted on 2005-04-29
Last Modified: 2008-01-09
I have problems with connecting MS Access 2000 database protected with password. I have tried to get help with this article: 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:

        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()

        '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

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

Hope that someone can help me,
Question by:miuku
    LVL 77

    Accepted Solution

    Hi miuku,
    This looks more relevant even though it's not the same version.

    Author Comment

    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()

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

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

    LVL 100

    Expert Comment

    Are you using the standard mdw file?

    look at

    Use the logon subreport sample


    Author Comment

    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.... =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now