This project has moved. For the latest updates, please go here.

Bug in SystemParameters.DatabasePageSize

Dec 14, 2010 at 1:46 PM

Using SystemParameters.DatabasePageSize as follows

  SystemParameters.DatabasePageSize = 8192;
   using (var instance = new Instance("CreateDatabase"))
   {
    instance.Init();
    using (var session = new Session(instance))
    {
     JET_DBID dbid;
     Api.JetCreateDatabase(session, Database, null, out dbid, CreateDatabaseGrbit.OverwriteExisting);
    }
   }

 

 

 

 

... will never work ("database page size mismatches engine size"), because

- SystemParameters.DatabasePageSize calls SystemParameters.SetIntegerParameter

- SystemParameters.SetIntegerParameter calls Api.JetSetSystemParameter

- Api.JetSetSystemParameter calls the type constructor for Api

- the type constructor for Api calls new JetApi();

- new JetApi() calls JetApi.DetermineCapabilities

- JetApi.DetermineCapabilities calls JetApi.GetVersionFromEsent

- JetApi.GetVersionFromEsent calls JetApi.JetInit: THIS WILL INITIALIZE ESENT FOR THE FIRST TIME WITH THE DEFAULT PAGE SIZE.

The instance.init()  that follows in the above code snippet will attempt to initialize the engine a second time, with the revised page size. Hence the error.

Please advise.

 

 
Dec 31, 2010 at 1:47 AM

That shouldn't be a problem because one the first instance is terminated ESENT goes back to an uninitialized state (but keeps the existing system parameters). This could cause a problem if you had multiple appdomains in the same process and were calling the static constructor in each one -- could that be the case?