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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
CJ_SCommented:
The problems appears in your connectionstring. You need to append an additional attribute called "Database Password=YourPassword;".

CJ.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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
CJ_SCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.