Adding, changing Access Database password

SimDuck

Member
Joined
Oct 25, 2004
Messages
21
Hi, I am trying to change a password on my Access database programmatically.

I have tried the sql query: "ALTER DATABASE tabletochange ADD/ALTER PASSWORD password" to no avail.

I am wondering if any one can tell me what the sql query is that I need to run to chang the password on my database is?

Thank you for your assistance
 
SimDuck said:
Hi, I am trying to change a password on my Access database programmatically.

I have tried the sql query: "ALTER DATABASE tabletochange ADD/ALTER PASSWORD password" to no avail.

I am wondering if any one can tell me what the sql query is that I need to run to chang the password on my database is?

Thank you for your assistance


I am using the sql query "ALTER DATABASE PASSWORD new password old password" and I get the error "cannot change password on a shared open database".

As this database isnt open any where else, what would be sharing it?

Is this the correct sql query to change the password or is there a better one?

I am using the oledb DBCommand.ExecuteNonQuery() command to update the database.

Your help is appreciated.
Thank you
 
To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.

Hope that hel[s, Chester
 
cpopham said:
To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.

Hope that hel[s, Chester

Hi Chester,

I added it to my connection string to make: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Y:\Work Computer Data\Work Data\Visual Basic Projects\Projects\Accounts Package\Version 1\Data\test.mdb;Exclusive=1"
and received this error when trying to open the database : "An unhandled exception of type System.Data.OleDb.OleDbException occurred in system.data.dll" With out the ;Exclusive=1, the database opens and I get the shared open database error.

This is my code that I am trying to change the password
Code:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source = " & TextBox1.Text & "\" & TextBox6.Text & ";Exclusive=1"
        
        Dim DBCon As New OleDbConnection(strConn)
        DBCon.Open()
        
        SQL = "ALTER DATABASE PASSWORD " & TextBox4.Text & TextBox5.Text
        Dim strCommand As String =  SQL
        Dim DBCommand As New OleDbCommand(strCommand, DBCon)
        execute the query
        Try
            DBCommand.ExecuteNonQuery()
        Catch ex As Exception

            MsgBox(ex.Message)
        Finally

        End Try
        DBCon.Close()
        DBCommand.Dispose()

Any assistance is welcome and appreciated.
Thank you again
Howard
 
Okay,

After Data Source take out the spaces, so it should look like this "Data Source=Data Source = Y:\Work Compute...."

Try to use one variable for your connection string like this:

Dim myDSrce as string = textbox1.text
myDSrce = myDsrc & "\"
myDSrce = myDsrce & textbox6.text

Then, your statement, should be:

Data Source= " & myDsrce & " ;Exlusive=1
Also, with the msgbox try this instead:

Messagebox.show(ex.message)

Then walk your code to make sure the correct path is being placed in your myDSrce variable.

Chester
 
Hi again Chester.

I have done what you suggested with:

Dim strDataSource As String = TextBox1.Text
strDataSource = strDataSource & "\"
strDataSource = strDataSource & TextBox6.Text


strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDataSource & ";Exclusive=1"

I still get the same exception error.
Thank you for your advice.
 
Did you put the debug pointer on the line of code where you declare the strDatasource variable? You can then walk the code with F8 one line at a time and then hover the mouse over the variable at each point on to be sure that the variable is getting the correct information. When you type the database name in your textbox6, are you using the database name and .mdb extension, like mydatabase.mdb or whtever type of Access database you are using as your backend? If you walk your code, you can see exactly what line of code is generating the error.

Chester
 
Hi, I did step through my code. The path & database are correct. When I leave the ";Exclusive=1" off of the connection string, then: DBCon.Open() works fine.

But when ";Exclusive=1" is part of the connection string, then the error is generated on DBCon.Open()

I am thinking that ";Exclusive=1" is causing an error and not opening the *.mdb in "non share mode".

Do you have any other suggestions?

Thank you so far. I have appreciated it.
 
APaule said:
Except ";Exclusive=1" try ";Mode=Share Deny Read|Share Deny Write"

APaule, I did this and the password change worked. I have ancountered another problem though and am wondering if you could help me.

If I run the sql query :
"ALTER DATABASE PASSWORD new password old password"
with a connection string of:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="strDataSource ";Mode=Share Deny Read|Share Deny Write"

and when I try to change the password to a new one, I get an error saying that the password isnt valid.

Do I need to change the sql query when the database has a password already?

Thank you
 
Back
Top