Back to UsefulDB4O in ASP.NET

Customize the configuration of the db4o database

If ,on the definition of the databases, do not specify anything, the db4o database will open with the default configuration settings.

To customize these settings should follow the next steps:

  1. Add the reference to the library Db4objects.Db4o.CS.dll on your project.
  2. Create a static class, and within it create a static method whose return value is of typeDb4objects.Db4o.CS.Config.IServerConfiguration
    namespace ExampleLibray
    {
        public static class DatabasesConfiguration
        {
            public static IServerConfiguration GetDatabaseProductsConfiguration()
            {
                var databaseConfig = Db4oClientServer.NewServerConfiguration();
    
                databaseConfig.Common.ActivationDepth = 0;
                databaseConfig.Common.StringEncoding  = StringEncodings.Unicode();
                databaseConfig.Common.WeakReferences  = false;
    
                return databaseConfig;
            }
        }
    }

    Line 7: get an empty instance of the class configuration
    Line 9,10,11: we set the settings that most interest us.
    Line 13: Return the configuration we created for the database

  3. Now we indicated in the web.config which method will be used to configure the database
    <db4o>
      <databases>
        <database
          alias="ProductsDatabase"
          serverType="EmbeddedServer"
          openServerRetriesOnLock="10"
          fileDb4oPath="/App_Data/products.db4o"
          assemblyWithDatabaseConfig="ExampleLibrary"
          staticMethodWithDatabaseConfig="ExampleLibrary.DatabasesConfiguration.GetDatabaseProductsConfiguration"
          />
      </databases>
    </db4o>

    Line 8: indicate the name of the assembly containing the class with the method ofconfiguration. It can be the same assembly of the application or another. In case of using the App_Code  folder indicate "App_Code" in the attribute assemblyWithDatabaseConfig  and in the attribute staticMethodWithDatabaseConfig only indicate class name + method name.

    Line 9: signature (name) full static method that returns the configuration of our database

  4. We can provide a method for all our databases or create a method for each.

Back to UsefulDB4O in ASP.NET

Last edited Dec 29, 2010 at 12:06 AM by pacoweb, version 3

Comments

No comments yet.