Search code examples
c#databaseexchange-serverjet

How to attach *.edb database using Extensible Storage Engine API?


I was trying to attach to Exchange Server database file using Managed Esent API but I got the next error: "Checksum error on a database page" or JET_errReadVerifyFailure on calling JetAttachDatabase. Can anybody explain what does it mean and how to fix it? This database was attached successfully from C++ application using the same API.

Code:

int pageSize;
Api.JetGetDatabaseFileInfo(fileName, out pageSize, JET_DbInfo.PageSize);

SystemParameters.DatabasePageSize = pageSize;

JET_INSTANCE jetInstance;
string jetInstanceName = Guid.NewGuid().ToString("N");
Api.JetCreateInstance(out jetInstance, jetInstanceName);

try
{
  SetSystemParameters(jetInstance, fileName, jetInstanceName);

  Api.JetInit(ref jetInstance);

  JET_SESID jetSessionId;
  Api.JetBeginSession(jetInstance, out jetSessionId, "admin", "password");

  try
  {
    Api.JetAttachDatabase(jetSessionId, fileName, AttachDatabaseGrbit.ReadOnly);
  }
  finally
  {
    Api.JetEndSession(jetSessionId, EndSessionGrbit.None);
  }
}
finally
{
    Api.JetTerm(jetInstance);
}

In SetSystemParameters method I set only SystemPath and TempPath parameters. May be I need to set any additional parameters to fix my problem? Or the version of my esent.dll is older than needed... Now my esent.dll version which in system32 folder is 5.1.2600.5512.

Thanks.


Solution

  • I've come across the same problem. And your guess is right, this is because the version difference. You will get this error if you try to open a Win7/Vista-made database by the WinXP esent engine.

    Unfortunately there is no way to fix it rather then upgrade your Windows. I mean legal way. Because if you just replece your esent.dll by the newer one, it will work. But this is not allowed by the Windows license.

    Here is another discussion of the problem: ESENT distribution rights