Password protect ms-access database using vb.net

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 3997 Views - Last Post: 24 January 2013 - 04:34 PM Rate Topic: -----

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:37 PM

Hello everybody,

I have an ms-access 2007 database which is created runtime in my small multi-user program
I want to password protect that database or the whole folder in which the database is located
Does anyone know the answer or a good basic tutorial on how to do that

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Password protect ms-access database using vb.net

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9059
  • View blog
  • Posts: 34,017
  • Joined: 12-June 08

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:42 PM

Wouldn't you typically do this in MSAccess itself?
Was This Post Helpful? 0
  • +
  • -

#3 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:45 PM

View Postmodi123_1, on 25 January 2013 - 01:12 AM, said:

Wouldn't you typically do this in MSAccess itself?


The database is created runtime
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9059
  • View blog
  • Posts: 34,017
  • Joined: 12-June 08

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:48 PM

Well you can use the ADOX object and jack with the user settings..

http://msdn.microsof...v=vs.85%29.aspx
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:49 PM

I'm pretty sure you can use a standard ALTER DATABASE sql statement and execute it against the database

If memory serves, it's something like
ALTER DATABASE PASSWORD [NewPassword][OldPassword]


But that's just off the top of my head
Was This Post Helpful? 0
  • +
  • -

#6 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:58 PM

View Postmodi123_1, on 25 January 2013 - 01:18 AM, said:

Well you can use the ADOX object and jack with the user settings..

http://msdn.microsof...v=vs.85%29.aspx


Used this line of code just after creating the database
ADOX.User.ChangePassword("", "Vishal1419")

but got an error
Referance to a non-shared member requires an object referance
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,293
  • Joined: 12-December 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 12:58 PM

This article is for Jet 4.0 but still relevant I believe. (This is for the database password, not user(s).)

My understanding is that we cannot implement user-level security in Access 2007 (accdb format), although it is still possible with Access 2003 (.mdb). So I'm not sure how this could be achieved with ADOX(?).

This post has been edited by andrewsw: 24 January 2013 - 01:07 PM

Was This Post Helpful? 0
  • +
  • -

#8 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:10 PM

View Postandrewsw, on 25 January 2013 - 01:28 AM, said:

This article is for Jet 4.0 but still relevant I believe. (This is for the database password, not user(s).)

My understanding is that we cannot implement user-level security in Access 2007 (accdb format), although it is still possible with Access 2003 (.mdb). So I'm not sure how this could be achieved with ADOX(?).


I dont understand this line
CurrentProject.Connection.Execute

Can you explain me what is CurrentProject
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,293
  • Joined: 12-December 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:26 PM

CurrentProject refers to the current database if you were using Access itself (the application). It doesn't really apply if you are creating code in VB.NET; you would use a Connection object, Command, etc..
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,293
  • Joined: 12-December 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:42 PM

Here is example code that connects to an Acess 2007 database, with an existing password:

        Dim cn As New OleDb.OleDbConnection

        cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
            & "C:\Users\Andrew\Documents\Staff Database.accdb;Jet OLEDB:Database Password=MyPassword;"
        cn.Open()


but it needs to be opened exclusively if you want to change/set the database password. I think you might need to use the ODBC driver to do this. Edited: CharlieMay's post below indicates this can be done with an OLEDB connection.

http://www.connectio...com/access-2007

This post has been edited by andrewsw: 24 January 2013 - 01:49 PM

Was This Post Helpful? 1
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:42 PM

Vishal1419,
Basically you can do the following

Dim con as New oleDB.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyTestDB.mdb;Mode=Share Deny Read|Share Deny Write;")
Dim cmd as New oledb.oledbcommand(ALTER DATABASE PASSWORD [test] null", con)
  con.open
    cmd.executenonquery
  con.close


This would be for setting an initial password, to change a password, null would be replaced with the old password.

The Mode in the connection string is very important as it needs to be done without any other connections to the database.

Of course, D:\MyTestDB.mdb would be replaced with the path and filename to your database in the connectionstring.
Was This Post Helpful? 0
  • +
  • -

#12 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:44 PM

Thank you andrewsw

Used the code below
cat.Create("PROVIDER = " & catProvider & "; Data Source = " & catPath & "\" & catName) 'Create Database
        
        Dim NewUser As New ADOX.User
        NewUser.Name = "Vishal"
        NewUser.ChangePassword("", "Vishal1419")
        cat.Users.Append(NewUser)


but getting one error
Object or provider is not capable of performing requested operation.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,293
  • Joined: 12-December 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 01:52 PM

As mentioned, ADOX with Access 2007 (accdb databases) cannot be used to create user-level security (AFAIK). My discussion and examples have been about creating a single (global) Access database password, as per your original post.

Added: User-level security is not enabled in Access 2007 (accdb) databases. You could, if you really wanted to, create an Access 2003 (.mdb) database. Or forget Access and create a MSSQL database :)

This post has been edited by andrewsw: 24 January 2013 - 01:55 PM

Was This Post Helpful? 0
  • +
  • -

#14 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 02:03 PM

View PostCharlieMay, on 25 January 2013 - 02:12 AM, said:

Vishal1419,
Basically you can do the following

Dim con as New oleDB.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyTestDB.mdb;Mode=Share Deny Read|Share Deny Write;")
Dim cmd as New oledb.oledbcommand(ALTER DATABASE PASSWORD [test] null", con)
  con.open
    cmd.executenonquery
  con.close


This would be for setting an initial password, to change a password, null would be replaced with the old password.

The Mode in the connection string is very important as it needs to be done without any other connections to the database.

Of course, D:\MyTestDB.mdb would be replaced with the path and filename to your database in the connectionstring.


Using the code given by you just after creating the database produces an error

You attempted to open a database that is already opened by user 'Admin' on machine 'VISHAL-PC'. Try again when the database is available.

But I dont have opened that file and if it is opened programatically then how to close it

View Postandrewsw, on 25 January 2013 - 02:22 AM, said:

As mentioned, ADOX with Access 2007 (accdb databases) cannot be used to create user-level security (AFAIK). My discussion and examples have been about creating a single (global) Access database password, as per your original post.

Added: User-level security is not enabled in Access 2007 (accdb) databases. You could, if you really wanted to, create an Access 2003 (.mdb) database. Or forget Access and create a MSSQL database :)/>


I am sorry,
I just tried the above code from some website
I dont want user level security but I want a password protected database without a public key but with a private key
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,293
  • Joined: 12-December 12

Re: Password protect ms-access database using vb.net

Posted 24 January 2013 - 02:10 PM

Try re-booting.. If the database has already been created then there may be a mis-matched .laccdb file in its folder that you could delete - before attempting to re-open the database (connection).

This post has been edited by andrewsw: 24 January 2013 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2