Solved

MS Access password

Posted on 2004-10-23
195 Views
Last Modified: 2010-04-24
Hi,

I'm using MS Access as database with my app and I want to prevent users from opening the database mainly to prevent structural modifications.

However, I want my app to be able to use the database without limitations.

I put a password in the database and tried to import it in the Visual Studio's Servers Explorer and invariably got an error message saying that no workgroup information is available.

Actually I don't want to authorize anyone to open/use the database except through the app.

Can anyone explain to me what's the problem and how I can resolve the issue?

Any help shall be greatly appreciated.  
0
Question by:Ghanisen
    7 Comments
     
    LVL 22

    Expert Comment

    by:CJ_S
    If you have no problems with the removal of the password on the actual database, then you can use the IPrincipal interface.

    IPrincipal allows you to set an identity to the current thread. Then you can call IsInRole(rolename) to check if the user can access the database.
    All you have to do is create a class which implements the IPrincipal interface. Then set the System.Threading.Thread.CurrentPrincipal to an instance of your class. Since you've implemented a working check of IsInRole you can now check in your database open function whether the current user has access or not.

    This approach does not protect the actual database when opened of course.
    0
     

    Author Comment

    by:Ghanisen
    Hi CJ S,

    Look I don't want each user to have or not permission to use the database. It's not on a network. All I want to do is set a OleDb connecting string for my mdb database that includes the password I've set in the database.

    This way I want the database to be opened only by my VB.NET application and not by users directely. They have to use it thru the application.

    My connection string (sConDB) is currently :

            sConDB = "Provider=Microsoft.Jet.OLEDB.4.0;"
            sConDB &= "Password=;User ID=Admin;"
            sConDB &= "Data Source=" & DBPath & ";"

    If my password (in the database) is MyPassword, how do I set the connection string to enable my application to open the database?

    I hope you have an answer. Thanks a lot.

    Note also that I don't know a thing about IPrincipal and how to use it.
    0
     
    LVL 22

    Expert Comment

    by:CJ_S
    The problems appears in your connectionstring. You need to append an additional attribute called "Database Password=YourPassword;".

    CJ.
    0
     

    Author Comment

    by:Ghanisen
    Hi CJ S,

    I tried:

    sConDB = "Provider=Microsoft.Jet.OLEDB.4.0;"
    sConDB &= "Database Password=Mypassword;"
    sConDB &= "Data Source=" & DBPath & ";"

    This connection string doesn't work.

    Can you give me the exact syntax the connection string should follow in this case? Thanks
    0
     
    LVL 22

    Accepted Solution

    by:
    0
     

    Author Comment

    by:Ghanisen
    Hi CJ S,

    Thank you very much for indicating where to find the correct connection string. I post it here for others who may need it.

    If you want to protect your MS Access database with a password and not use use workgroups then the syntax for the connection string is:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;"

    However, if you use stored procedures in your MS Access database, you have to set the authorizations for the Administrator to edit/use stored procedures by selecting MSysObjects and MSysQueries under the security assistant within Access (To be opened in exclusive mode).

    I discovered that when I tried to use my stored procedures after setting the password protection.

    Thanks again CJ S. You sure deserve the 500 points.
    0
     
    LVL 22

    Expert Comment

    by:CJ_S
    Thanks! Glad I could help.

    CJ.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    934 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

    13 Experts available now in Live!

    Get 1:1 Help Now