MS Access password

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.  
GhanisenAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CJ_SCommented:
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
 
GhanisenAuthor Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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

CJ.
0
 
GhanisenAuthor Commented:
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
 
GhanisenAuthor Commented:
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
 
CJ_SCommented:
Thanks! Glad I could help.

CJ.
0
All Courses

From novice to tech pro — start learning today.