ODBC-connection to access DB with password lazarus / 16-Databases ---------------------------------------------------------------------- timmermanj · 2010-08-17 09:28 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 · 2010-08-17 10:26 You can try setting "conDatabase.UserName" ? ---------------------------------------------------------------------- timmermanj · 2010-08-17 12:17 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 · 2010-08-17 19:49 Make sure that the UserName does not have a default value. ---------------------------------------------------------------------- timmermanj · 2010-08-23 07:43 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 · 2010-08-23 09:18 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 ---------------------------------------------------------------------- timmermanj · 2010-08-23 11:50 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 · 2010-08-23 11:58 i didn't know, i just tried ---------------------------------------------------------------------- Lacak2 · 2010-08-24 06:00 http://wiki.freepascal.org/ODBCConn#TODBCConnection_properties