SimDuck Posted May 6, 2005 Posted May 6, 2005 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 Quote
SimDuck Posted May 11, 2005 Author Posted May 11, 2005 Quote 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 isn't 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 Quote
cpopham Posted May 11, 2005 Posted May 11, 2005 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 Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
SimDuck Posted May 11, 2005 Author Posted May 11, 2005 Quote 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 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 Quote
cpopham Posted May 11, 2005 Posted May 11, 2005 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 Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
SimDuck Posted May 13, 2005 Author Posted May 13, 2005 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. Quote
cpopham Posted May 13, 2005 Posted May 13, 2005 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 Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
SimDuck Posted May 19, 2005 Author Posted May 19, 2005 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. Quote
APaule Posted May 20, 2005 Posted May 20, 2005 Except ";Exclusive=1" try ";Mode=Share Deny Read|Share Deny Write" Quote
SimDuck Posted June 7, 2005 Author Posted June 7, 2005 Quote 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 isn't valid. Do I need to change the sql query when the database has a password already? Thank you Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.