Solved

Change Access Databse Password

Posted on 2006-07-23
3
308 Views
Last Modified: 2012-05-05
Hi Experts
How I can Change MSAccess Password In Delphi?
0
Comment
Question by:mahdiparak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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