: Hi!
:
: I have a database created in MS Access. It is protected by a password. I also have an application working with that database. I would like to know whether and how it is possible to change this database password from the application (I'm using ADO to connect to it).
:
: Any help highly appreciated.
:
Ok, after a couple of months I was finally able to find the solution myself. So, if anyone is interested, here is how to make it. (I don't have Delphi available at hand, so I hope I remember it correctly)
1. Use ADOConnection component from the ADO panel to connect to your Access database. When building a connection string, choose Microsoft Jet OLE DB 4.0 provider. Your connection string then should like something like
Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\Program files\TestBase.mdb;
Persist Security Info=False
Note that in order to change password you should open database exclusively. To do that, in ADOConnection mode property choose ShareExclusive option.
2. You will also need some component capable of dealing with SQL. I used ADOCommand. Put it to form and connect to ADOConnection you have created before.
3. When you want to change database password, use your ADOCommand component. Try the following code:
cs := 'ALTER DATABASE PASSWORD NewPassword OldPassword';
ADOCommand1.CommandText := cs;
ADOCommand1.Execute;
Here cs is a string and instead NewPassword and OldPassword type in the corresponding values. If password is not set, type NULL in place of OldPassword.
Can you believe it? As simple as that!
P.S. you can even manage user-level security from Delphi. If interested, here is how to do it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acadvsql.asp