Link to home
Start Free TrialLog in
Avatar of Erik N
Erik N

asked on

Login to ACCESS-db...

Need some advice on how to avoid the login-prompt when connecting to an access-database. I use Delphi 4 Pro. Using ODBC-alias pointing at the db..

Thanx !
/Erik N
Avatar of aubs
aubs

Hi Erik

If you connect to a database via the TDatabase component, you can set the TDatabase component LoginPrompt property to false.
Sorry, I should have explained better.

Drop a TDatabase component (from the Data Access tab) on a form and set the alias to the one you are already using.

Set DatabaseName to some arbitrary new alias name, like 'Accesstest'.

Set the loginprompt property to False.

Set the aliases of all other data aware components on the form to this new alias 'AccessTest'.

Regards Aubs
Hi Erik,

You can write an OnLogin event handler on your TDatabase component as follows:

procedure TForm1.MyDBLogin(Database: TDatabase; LoginParams: TStrings);
begin
  LoginParams.Values['USER NAME'] := 'admin';
  LoginParams.Values['PASSWORD']  := '';
end;

Set TDatabase component properties LoginPrompt to false and KeepConnection to true.

Regards, Geo
i did this for someone else ,it basically backs up what aubs said:

Odbc:

1:   Open Control Panel, and then select ODBC DataSources (32bit) .
2:   When the Data Source Administrator appears, Click Add.
3:   find the one that says  Microsoft Access Driver (*.mdb)
     click it and click finish.
4:   A dialog will popup called ODBC Microsoft Access Setup
5:   in "data source name" edit box well call it "MyAccess"
6:   description well say is "tesing msaccess connection".
7:   click select and find your .mdb file click ok to select it.
8:   click "advanced" and make sure login name and password are blank.
9:   close advanced.
10:  close microsoft access setup dialog
11:  close the  Data Source Administrator.


delphi:

1:  start or restart delphi if its already running.
2:  start a new project
3:  drop a ttable,tdbgrid,tdatasource,tdatabase on form.

    in object inspector:

4:  datasource1 dataset : table1
5:  dbgrid datasource   : datasource1
6:  database1 aliasname : MyAccess  
7:  database1 databasename : MyAccessDB //tyope some name
8:  database1 loginprompt : false
9:  table1 databasename : MyAccessDB  //is now selectable
10: table1 tablename : select a table
11: database1 connected : true
12: table1 active : true

and viola table should appear with no login prompt
set loginprompt to true and you get the prompt or set to
false and get no prompt.

hope this helps someone somewhere

Regards Barry
Avatar of Erik N

ASKER

All these worked fine except setting the login params using the ODBC-administrator. My params in the ODBC-administrator is already blanked..

Who want some points ?

/Erik N
Aubs was first ..
For a change...
Avatar of Erik N

ASKER

OK aubs... Propose....
ASKER CERTIFIED SOLUTION
Avatar of aubs
aubs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial