Need to host a subversion repository? Try our hosted development tools.

Delphi and Kylix

Moderators: pritaeas
Number of threads: 7198
Number of posts: 18951

This Forum Only
Post New Thread

Report
Changing MS Access database password from application Posted by SaMo on 16 May 2004 at 11:01 PM
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.
Report
Re: Changing MS Access database password from application Posted by SaMo on 18 Jul 2004 at 11:31 PM
: 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



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.