Solved

Change Access Databse Password

Posted on 2006-07-23
3
305 Views
Last Modified: 2012-05-05
Hi Experts
How I can Change MSAccess Password In Delphi?
0
Comment
Question by:mahdiparak
3 Comments
 
LVL 9

Expert Comment

by:sun4sunday
ID: 17163162
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21080111.html

copying the solution

var
  db1, db2, fp1, fp2 : string;
begin
  db1:='c:\test\test.mdb';    // original flename
  db2:='c:\test\new.mdb';   // new filename
  fp1:='password';        //original file password
  fp2:='password';       //new file password
  try
    StatusBar.SimpleText:='Loading driver...';
    v := CreateOLEObject('JRO.JetEngine');
    try
      v.CompactDatabase('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + db1 +
                        ';Persist Security Info=False' + fp1,
                        'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + db2 +
                        'x; Jet OLEDB:Engine type=5'+ fp2);
    except
    on E:Exception do
           ShowMessage(E.Message);
    end;
  finally
    v := Unassigned;
    StatusBar.SimpleText:='Done.';
  end;
end;

sun4sunday
0
 
LVL 28

Expert Comment

by:TName
ID: 17163173

Hi, are you using ADO? Try

ALTER DATABASE PASSWORD MyNewPassword MyOldPassword

e.g.:
ADOCommand1.CommandText := 'ALTER DATABASE PASSWORD MyNewPassword MyOldPassword';
ADOCommand1.Execute;

see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acadvsql.asp

and you might want to have a look at
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21900292.html

0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 17163341
Another alternative example.

Russell

----

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj, ActiveX; // Include Variants for D6 and up

type
  TForm1         = class(TForm)
     Button1:    TButton;
     procedure   Button1Click(Sender: TObject);
  private
     // Private declarations
  public
     // Public declarations
  end;

var
  Form1:         TForm1;

implementation
{$R *.DFM}

const
  adModeShareExclusive =  12;

function UpdateDBPassword(FileMDB: String; OldPassword, NewPassword: String): Boolean;
var  ovConn:        OleVariant;
begin

  // Create ADO connection
  ovConn:=CreateOleObject('ADODB.Connection');
  try
     // Set exclusive mode
     ovConn.Mode:=adModeShareExclusive;
     try
        // Open the database
        ovConn.Open(Format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source="%s";Jet OLEDB:Database Password="%s"', [FileMDB, OldPassword]));
        // Update the password
        ovConn.Execute(Format('ALTER DATABASE PASSWORD `%s` `%s`', [NewPassword, OldPassword]));
        // Close the connection
        ovConn.Close;
        // Success
        result:=True;
     except
        // Exception, return failure
        result:=False;
     end;
  finally
     // Clear the object reference
     ovConn:=Unassigned;
  end;

end;

function SetDBPassword(FileMDB: String; Password: String): Boolean;
var  ovConn:        OleVariant;
begin

  // Create ADO connection
  ovConn:=CreateOleObject('ADODB.Connection');
  try
     // Set exclusive mode
     ovConn.Mode:=adModeShareExclusive;
     try
        // Open the database
        ovConn.Open(Format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source="%s"', [FileMDB]));
        // Update the password
        ovConn.Execute(Format('ALTER DATABASE PASSWORD `%s` NULL', [Password]));
        // Close the connection
        ovConn.Close;
        // Success
        result:=True;
     except
        // Exception, return failure
        result:=False;
     end;
  finally
     // Clear the object reference
     ovConn:=Unassigned;
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  // Set initial password
  if SetDBPassword('c:\db1.mdb', 'Testing') then
  begin
     // Update password
     UpdateDBPassword('c:\db1.mdb', 'Testing', 'New Password');
     // Remove the password
     UpdateDBPassword('c:\db1.mdb', 'New Password', '');
  end;

end;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 284
Help on project with Soap 10 47
TServerSocket - file via sendbuf or Text via sendtext ? 1 42
Delphi inherited method 6 60
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now