How to do a Extensible Storage Engine (JetBlue) repair in code?

836 views Asked by At

I'm using ESE (JetBlue) in an app, when JetAttachDatabase is called it returns JET_errDatabaseDirtyShutdown. What am I supposed to do in my app? my desire is for any uncommeted transactions to be deleted

2

There are 2 answers

1
Laurion Burchall On BEST ANSWER

Log recovery will be done automatically by the call to JetInit, which will automatically rollback uncomitted transactions. In order for JetInit to work it has to find the logfiles so in this case you have probably either:

  1. Deleted the logfiles. Don't do that.
  2. Didn't set the logfile path correctly. Always set the same logfile path when initializing so that ESE can find the logs.
  3. Moved the database. The logs contain a hard-coded path to the database so moving the database breaks recovery. To deal with this you can set the alternate recovery path system parameter to the directory containing the database.
0
egray On

You can configure your application to automatically attempt to clear the "dirty shutdown" by adding the following after JetCreateInstance() and before JetInit(). Yes the order of these things is important:

Api.JetSetSystemParameter(instance, JET_SESID.Nil, Server2003Param.AlternateDatabaseRecoveryPath, 0, Path.GetDirectoryName(databasePath));

(above sample is in C#, but you get the point...)

The last parameter is the location where you'd like the repaired database to appear, so most likely that'd be the same directory as the dirty database file.