Question

we are using Db4o in our project.

I have some automatic tests where is tested persistence of objects. The problem is, I can't open/create the database twice. I have two helper methods for geting the object container. But when the method is called second time the "ArgumentException: Configuration already used." is thrown. I closed and disposed the previous objectcontainer ofcourse.

What I do wrong?

CODE:

public static IObjectContainer GetEmptyTestingDatabase() {
    var tempDir = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
    string dbFilePath = Path.Combine(tempDir, "UNIT-TESTING.db4o");
    if (File.Exists(dbFilePath)) {
        File.Delete(dbFilePath);
    }

    var cfg = Db4oFactory.Configure();
    cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy()));
    cfg.Add(new TransparentActivationSupport());

    var db = Db4oFactory.OpenFile(cfg, dbFilePath);
    return db;
}
public static IObjectContainer GetMemoryDatabase() {
    string dbFileName = Guid.NewGuid().ToString().ToString();

    var cfg = Db4oFactory.Configure();
    cfg.Storage = new Db4objects.Db4o.IO.PagingMemoryStorage();
    cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy()));
    cfg.Add(new TransparentActivationSupport());

    var db = Db4oFactory.OpenFile(cfg, dbFileName);
    return db;
}
Was it helpful?

Solution

You are using deprecated db4o methods. The problem is that Db4oFactory.Configure() returns a static config object; this method is there only for backward compatibility.

If you are using a newer db4o version use Db4oEmbedded.NewConfiguration() instead. Otherwise (if you really need to stick to an older db4o version) using Db4oFactory.NewConfiguration() should also work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top