Recent

Author Topic: ODBC-connection to access DB with password  (Read 12990 times)

timmermanj

  • New member
  • *
  • Posts: 39
ODBC-connection to access DB with password
« on: August 17, 2010, 11:28:16 am »
I hope anybody can help me with this one...

I've created a odbc-connection to a ms-access database.
It works fine without a password but from the moment i secure the database with a password it's a different story.

Beneath you can see the code i try to use:

conDatabase.Driver:= 'Microsoft Access Driver (*.mdb)';
  conDatabase.Params.Add('DBQ= C:\blabla\test.mdb');
  conDatabase.Password:= 'test';
  conDatabase.Connected:= True;


This didn't work...
Anybody any idea how to make this work?

Thanks in advance!
Jeffrey

bonmario

  • Sr. Member
  • ****
  • Posts: 283
Re: ODBC-connection to access DB with password
« Reply #1 on: August 17, 2010, 12:26:43 pm »
You can try setting "conDatabase.UserName" ?

timmermanj

  • New member
  • *
  • Posts: 39
Re: ODBC-connection to access DB with password
« Reply #2 on: August 17, 2010, 02:17:35 pm »
I've secured my access database without a username.
If someone tries to open the database with access they only have to fill in a password, no username.

I did this before in delphi with a ADO-connection. It look like this:

conDatabase.Provider:= 'Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=test';
  conDatabase.ConnectionString:= 'C:\blabla\test.mdb';
  conDatabase.LoginPrompt:= False;
  conDatabase.Mode:= cmShareDenyNone;
  conDatabase.Open;


Maybe in Lazarus we have to do something likewise?

Please advice!

Thanks!
Jeffrey

spitofland

  • New member
  • *
  • Posts: 26
Re: ODBC-connection to access DB with password
« Reply #3 on: August 17, 2010, 09:49:02 pm »
Make sure that the UserName does not have a default value.

timmermanj

  • New member
  • *
  • Posts: 39
Re: ODBC-connection to access DB with password
« Reply #4 on: August 23, 2010, 09:43:40 am »
I've left the username of the TODBCconnection component blank and I've filled in the password value but still i'm not able to connect to the access database.

The attachment contains a mini project where I show what i did so far.
Maybe someone can tell me why it's not working.
The password of the access database is "test".

P.S. If i try to connect to a database without asking a password, the program connects to the database.
So the program should work without passwords.

It searches automatically the database, as long as the database is in the test folder and has the same name as the program can find the database.

I hope somebody can help me with this!
Thanks a lot!
Jeffrey

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: ODBC-connection to access DB with password
« Reply #5 on: August 23, 2010, 11:18:49 am »
Have you tried with username "Admin", it's the default value for any Access dB.

Edited:


My bad, it was more simple than that. Default username is really Admin but you don't need it.
In fact, you can't use the password of the TODBCConnection with any Access DB,
it's always returning "Wrong password".

Here is the trick:

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var
  dbPath: string;
  dbPass: string;
begin
  //Set your DB path
  dbPath := Application.exename;
  dbPath:= ChangeFileExt(dbPath, '.mdb');

  //Set your password
  dbPass := 'test';

  //Setup params
  conDatabase.Driver:= 'Microsoft Access Driver (*.mdb)';
  conDatabase.Params.Add('DBQ= ' + dbPath);
  conDatabase.Params.Add('PWD= ' + dbPass);

  //Connect
  conDatabase.Connected:= true;

  if conDatabase.Connected = true Then showmessage('connected');
end;

Best Regards,
Fabien Wang aka Dr4x
« Last Edit: August 23, 2010, 11:34:33 am by Dr4x »
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

timmermanj

  • New member
  • *
  • Posts: 39
Re: ODBC-connection to access DB with password
« Reply #6 on: August 23, 2010, 01:50:54 pm »
Thanks a lot!!!

It works! If you didn't told me this I would never found this.
How did you know? Are there some tutorials with this info?
I've searched Google for a while but didn't found this.

Thanks again!!!
Jeffrey

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: ODBC-connection to access DB with password
« Reply #7 on: August 23, 2010, 01:58:19 pm »
i didn't know, i just tried  O:-)
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint