This project has moved and is read-only. For the latest updates, please go here.

Accessing Exchange Database

Dec 10, 2010 at 11:05 AM

Does anybody had accessed an Mailbox Database with this code? I can't.


It gives an PageSizeMismatch error in the call to JetIni in the case bellow. If I don't specify the page size as 8K before JetIni, it gives the same error but in the call to JetOpenDatabase.


        public static void Main(string[] args)
            JET_INSTANCE instance;
            JET_SESID sesid;
            JET_DBID dbid;
            JET_TABLEID tableid;

            JET_COLUMNDEF columndef = new JET_COLUMNDEF();
            JET_COLUMNID columnid;

            // Initialize ESENT. Setting JET_param.CircularLog to 1 means ESENT will automatically
            // delete unneeded logfiles. JetInit will inspect the logfiles to see if the last
            // shutdown was clean. If it wasn't (e.g. the application crashed) recovery will be
            // run automatically bringing the database to a consistent state.
            SystemParameters.DatabasePageSize = 8192;
            Api.JetCreateInstance(out instance, "instance");
            //Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.DatabasePageSize, 8192, null);
            Api.JetInit(ref instance);

            int Valor1;
            JetGetDatabaseFileInfo("H:\\TEMP\\Storage Group 15\\ST15 Mailbox.edb", out Valor1, sizeof(int), 17);

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

                // Create the database. To open an existing database use the JetAttachDatabase and
                // JetOpenDatabase APIs.
                Api.JetAttachDatabase(sesid, "H:\\TEMP\\Storage Group 15\\ST15 Mailbox.edb", AttachDatabaseGrbit.ReadOnly);

                Api.JetOpenDatabase(sesid, "H:\\TEMP\\Storage Group 15\\ST15 Mailbox.edb", null, out dbid, OpenDatabaseGrbit.ReadOnly);

                foreach (string table in Api.GetTableNames(sesid, dbid))
                Api.JetEndSession(sesid, EndSessionGrbit.None);


Dec 31, 2010 at 2:48 AM

You can't access an Exchange database with ESENT. The formats are different and the database schema is undocumented and extremely complex.

Oct 3, 2011 at 7:11 PM

The problem is not connected with the Exchamge databse format. The following code is enough to reproduce the problem:

SystemParameters.DatabasePageSize = 8192;
using (Instance instance = new Instance("stocksample"))
{   instance.Parameters.CircularLog = true;

You see, no particular database. The problem is just with initialization code. I've face it too. :(

Is there any workaround?...

Oct 3, 2011 at 7:18 PM

I've found an answer in this thread:

Deleting log files solves the problem.