Problems trying to access/attach ESE database using ManagedEsent

1.7k Views Asked by At

I'm trying to read an ESE database (.edb) using the ManagedEsent libraries. However, I'm getting an error at the time of setting up the database. The error appears to be coming up at the time of attaching the database (calling JetAttachDatabase()).

The error message I'm getting is "Soft recovery is intended on a backup database. Restore should be used instead".

Below is my code:

JET_INSTANCE instance;
JET_SESID sesid;

Microsoft.Isam.Esent.Interop.SystemParameters.DatabasePageSize = 8 * 1024;

Api.JetCreateInstance(out instance, Guid.NewGuid().ToString());
Api.JetInit(ref instance);

JET_DBID dbid;
JET_COLUMNID columnid;
JET_TABLEID tableid;
JET_COLUMNDEF columndef = new JET_COLUMNDEF();

Api.JetBeginSession(instance, out sesid, null, null);

Api.JetAttachDatabase(sesid, @"Blah.edb", AttachDatabaseGrbit.None);

Api.OpenDatabase(sesid, @"Blah.edb", out dbid, OpenDatabaseGrbit.None);

The exception I'm getting is:

Microsoft.Isam.Esent.Interop.EsentSoftRecoveryOnBackupDatabase
Soft recovery is intended on a backup database. Restore should be used instead
at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in e:\src\codeplex_svn\codeplex\EsentInterop\Api.cs:line 2894
at Microsoft.Isam.Esent.Interop.Api.JetAttachDatabase(JET_SESID sesid, String database, AttachDatabaseGrbit grbit) in e:\src\codeplex_svn\codeplex\EsentInterop\Api.cs:line 372

Any ideas what could be causing this? Is the .edb file I'm attaching possible invalid?

2

There are 2 best solutions below

2
Martin Chisholm On

Where did you get the database? What you did should work for a Cleanly-shut-down database. You don't need the transaction log files for these databases. But there are also Dirty databases (when JetTerm didn't complete gracefully). You'll need the transaction log files for those. And also Backed-up databases, which are slightly different again. For these databases, you need to call JetRestore.

-martin

4
Joe On

I was able to access the database after running the EsentUtl utility to repair the database file:

esentutl /p Blah.edb

After running this, I can attach/open the database and read from the tables in the database. I'm not sure what the repair has actually done to the file though (e.g. if it is possibly now missing some data or something).