#1 2020-07-07 10:06:40

chopseo
Member
Registered: 2020-07-07
Posts: 5

Newbie connecting to an .accdb Database

Hello,

Im just getting started with the mORMot framework and need to connect to an .accdb database.

Any sample code or link would be great.

I did some connection attempts with the TOleDBJetConnectionProperties class without success.

Usually I connect with the Microsoft.ACE.OLEDB.12.0 provider to this kind of database.

I did a search and found nothing here on the forum.

Im on Windows 7 with Delphi 2006.

Thx and greeting
chopseo

Offline

#2 2020-07-07 10:14:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Newbie connecting to an .accdb Database

Did you try with TOleDBJetConnectionProperties?

Offline

#3 2020-07-07 11:13:06

chopseo
Member
Registered: 2020-07-07
Posts: 5

Re: Newbie connecting to an .accdb Database

Thx for your fast response!

Yes, I did some tests with TOleDBJetConnectionProperties without luck.

I experimented in the GitHub\mormot\SQLite3\Samples\15 - External DB performance project and tried to alter the test to connect with my .accdb database:

Test( TOleDBJetConnectionProperties,'....\TestDb.accdb','','','','',true);

Offline

#4 2020-07-07 14:05:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Newbie connecting to an .accdb Database

Please try the new TOleDBACEConnectionProperties class.
Check https://synopse.info/fossil/info/f1af277af9

Offline

#5 2020-07-09 17:25:43

chopseo
Member
Registered: 2020-07-07
Posts: 5

Re: Newbie connecting to an .accdb Database

Thx for providing the new connection class!

I tried it, but unfortunately without success:

Im still changing the mormot\SQLite3\Samples\15 - External DB performance project for my tests.

Im calling the new with class with
Test(TOleDBACEConnectionProperties,'...\TestDb.accdb','','','','',true);


If my TestDb doesnt exists, I got an exception at

function TOleDBConnectionProperties.CreateDatabase: boolean;
var Catalog: _Catalog;
    DB: OleVariant;
begin
.
.
.
        DB := Catalog.Create(ConnectionString); // <- exception here
.
.

end;

If my TestDb exists, I got an exception at

function TOleDBConnectionProperties.GetSchema(const aUID: TGUID;
  const Fields: array of RawUTF8; var aResult: IRowset): boolean;
var i, res, n: integer;
    C: TOleDBConnection;
    SRS: IDBSchemaRowset;
    PG, OG: PGUID;
    PI, OI: PInteger;
    Args: array of Variant;
begin
.
.
.
  C.fSession.QueryInterface(IDBSchemaRowset,SRS); // exception here
.
.
.
end;


My connection string is:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=...\TestDb.accdb;Initial Catalog=ace.1;User Id=;Password=;


Let me know, how I can give you more detailed information about the problem.

Offline

#6 2020-07-10 07:26:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Newbie connecting to an .accdb Database

1) please follow the forum rules, and don't post a lot of code in the forums

2) what is the exception full message? (this is the main useful information)

Offline

#7 2020-07-13 08:13:53

chopseo
Member
Registered: 2020-07-07
Posts: 5

Re: Newbie connecting to an .accdb Database

Im sorry for posting code. I tried to delete all the irrelevant part.

Not posting the exception message was kind of stupid of me though.

This is the exception message, if the database not exists (translated from german):
Exception at $756DC5AF. Error in an OLE DB process consisting of several steps. Check the individual OLE DB status values, if available. Data was not processed.

If the database exists, I get the message
Exception class EOleSysError with message 'OLE error 80040E21'


If I can do any more tests let me know.

Thx and greetings.

Offline

#8 2020-07-13 08:20:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Newbie connecting to an .accdb Database

If you follow http://www.adopenstatic.com/faq/80040e21.asp information, it means:

Scenario 2 - Error occurs when opening a connection
The error will occur when you call the .Open() method on an ADO Connection object. The error is caused by attempting to specify a value for an unsupported property in the Connection Object's connection string.

Please try to find out which correct connection string does pass.

Offline

#9 2020-07-14 07:33:50

chopseo
Member
Registered: 2020-07-07
Posts: 5

Re: Newbie connecting to an .accdb Database

I had success with connecting and creating an accdb Database!

The problem was the "Initial Catalog=ace.1" part of the connection string, which the GitHub\mormot\SQLite3\Samples\15 - External DB performance project added automatically.

I started an own test project with the call

Props := TOleDBACEConnectionProperties.Create( '....\TestDb.accdb', '', '', '' );

and got the working connection string:

'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=....\TestDb.accdb;User Id=;Password=;'

The fDBMS: TSQLDBDefinition property of Props: TOleDBACEConnectionProperties is still dJet. Is this correct?

Also I noticed that there is no call TOleDBACEConnectionProperties.RegisterClassNameForDefinition; in the initialization section of the SynOleDB unit.

Everything worked though.

Thx for your support and greetings.

Offline

#10 2020-07-14 09:48:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Newbie connecting to an .accdb Database

We have now registered the TOleDBACEConnectionProperties class for settings.
Check https://synopse.info/fossil/info/bcc427fb32

Thanks for the feedback!

Offline

Board footer

Powered by FluxBB