Board index » delphi » Problemds with ModifyAlias and MsAccess

Problemds with ModifyAlias and MsAccess

I am trying to develop an application which will allow the user to
connect to different
MSAccess databases.  I am trying to do this by modifying an existing
alias that I defined
using BDEAdmin using the following code:

procedure TForm1.Button1Click(Sender: TObject);
var
  AliasParams: TStringList;
begin
  AliasParams := TStringList.Create;
 try
   with AliasParams do
   begin
     Add('DATABASE NAME=F:\Lockheed Mapping Project\Source Compare
Application\Changed.mdb');
     Add('USER NAME=');
     Add('OPEN MODE=READ/WRITE');
     Add('LANGDRIVER=');
     Add('PASSWORD=');
   end;
   Session1.ModifyAlias('ChangedData',AliasParams)
 finally
     AliasParams.Free;
 end;
 DataBase1.Connected := True;
end;

The code successfully modifies the path, however, I get an error message
that the password is invalid.  There is no password on the database.

Any help would be appreciated.

 

Re:Problemds with ModifyAlias and MsAccess


Let's say you have a dummy MSACCESS alias defined named ALLACCESS. Here
is how I set the path of this dummy alias to anywhere I want:

var
        t:tstringlist;
begin
t := nil;  
try  
    table1.databasename := 'ALLACCESS';
    t := tstringlist.create;
    Session.GetAliasParams('ALLACCESS',t);
    path := opendialog1.filename;      
    t.strings[0] := 'database name=' + path;
    session.modifyalias('ALLACCESS',t);

    t.clear;
    Session.GetTableNames('ALLACCESS','',False, False, t);

    //Normally, you would now do something like
    //show a listbox on a modal form  
    //to let the client pick the table name
    //But since this is just a test, we'll just
    //use the first table in the list

    if t.count > 0 then begin //if not an empty database
        table1.tablename := t.strings[0]; //use the first table listed
        table1.open;
   end;
   finally
        if assigned(t) then t.free;
   end;
end;

Re:Problemds with ModifyAlias and MsAccess


I forgot to mention in my previous post that the password problem you
are having may be caused by changing default values of the native
driver using Add('PASSWORD=').
That is why I sent you code that doesn't alter default settings
other than the database name.

On Tue, 02 Jun 1998 17:28:22 -0700 John C. Pinsonnault said something
like...
:I am trying to develop an application which will allow the user to
:connect to different
:MSAccess databases.  I am trying to do this by modifying an existing
:alias that I defined
:using BDEAdmin using the following code:
:
:var
:  AliasParams: TStringList;
:begin
:  AliasParams := TStringList.Create;
: try
:   with AliasParams do
:   begin
:     Add('DATABASE NAME=F:\Lockheed Mapping Project\Source Compare
:Application\Changed.mdb');
:     Add('USER NAME=');
:     Add('OPEN MODE=READ/WRITE');
:     Add('LANGDRIVER=');
:     Add('PASSWORD=');
:   end;

Other Threads