I use Delphi 2010 and adoconnection to connect to Accdb. I save all in c:\Delphi folder but adoconnection when choosing the database reports the error (looks for it on Desktop).
String: Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Persist Security Info=False
What am I doing wrong? How to set the default working folder?
Thanks
1 Answer
You should point to full qualified DB filename on connection string.
ConnectionString := 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Delphi\Database1.accdb;Persist Security Info=False';
Or if your DB file stored relative to your exe path it should be:
ConnectionString := 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=' + ExtractFilePath(ParamStr(0)) + 'Database1.accdb' + ';Persist Security Info=False';
EDIT The following statement isn't True, it's my false memories: But for note, as my experience you should using Microsoft Access Databases (2002-2003 format)(.mdb), newest / latest MSAccess DB format isn't supported by current ADOConnection version.*
-
@coderbuzz, why do you say which the latest version of MSAccess are not supported by ADO?– RRUZMar 29, 2011 at 3:39
-
My latest experience with Access Database format .accdb talking* like that, or I'm missing something (select another driver (version) maybe). Just in case, the problem (I forgot exact error message) gone when I use *.mdb format, not *.accdb . CMIIW Mar 29, 2011 at 3:50
-
@coderbuzz: Look at your drivers, coz I am using accdb format with AdoConnection without problems. Don't have the code here (am at work) but you basically need to make sure that you select a driver that understands the accdb format. Older drivers of course won't. Access2007 db driver is probably called something like "Microsoft Access 12 OleDB driver" (not sure about the 12 but it should be close) Mar 29, 2011 at 6:07
-
Drivers are not the issue. Design time adoconnection looses track of folders. Happens with accdb and mdb. Anyone had this problem?– user645976Mar 29, 2011 at 6:47
-
@Marjan Venema: Just tried my self a minutes ago, you right, no problem using .accdb. It's my false 'memories; some my project deployment (using access db) require to deploy to machine that hasn't office installed, Windows XP. So for safe reason I choose .mdb format :) Thanks for clarify that. (Answer edited) Mar 29, 2011 at 7:20