Search code examples
esentextensible-storage-engine

JetAttachDatabase returns -1213


I am trying to read into some existing and unmounted ESE database files. I have been playing around with one .dat file rather successfully. But when I try to open a existing database with PageSize that is equal 32768 I get an error.

Here's my code (without error-handling):

FError := JetSetSystemParameter(&FInstance, nil, JET_paramRecovery, FPagesize, "off");
FError := JetCreateInstance(&FInstance, 'myinstance');
FError := JetInit(&FInstance);
FError := JetBeginSession(FInstance, &FSessionId, nil, nil);
FError := JetAttachDatabase(FSessionId, FFilename, JET_bitDbReadOnly);

It fails at the JetAttachDatabase call which returns an -1213 code. Am I doing something wrong?

I am running a Windows 7 32bit.


Solution

  • The Esent engine uses a certain page size by default. If I'm not mistaken it's 4K. You will have to tell the engine that the database you want to open has a different page size. Use something like that:

    FError := JetSetSystemParameter(&FInstance, nil, JET_paramDatabasePageSize, 32768, nil);
    

    If you open up different databases all the time, you might want to have your application checking out and setting the pagesize automatically.