Search code examples
clientdb4o

How can a client query a db4o server?


I've set up a db4o server and client. My client calls are not working.

What's puzzling to me is that the db4o examples show how the client can close the server, but not how to get and save data. See: http://community.versant.com/Documentation/Reference/db4o-7.12/java/reference/Content/client-server/networked/simple_db4o_server.htm

If I start the db4o server, and run netstat, I can see that the port is open. And on the client, I can do things like this:

Debug.WriteLine(db.Ext().IsClosed().ToString());

And that returns False, which is good.

But when I try to get or save data, it doesn't work. When saving data, it appears to work, but I don't see the data in the DB. When trying to retrieve the object, I get this error:

Db4objects.Db4o.Ext.Db4oException: Exception of type 'Db4objects.Db4o.Ext.Db4oException' was thrown. ---> System.ArgumentException: Field '_delegateType' defined on type 'Db4objects.Db4o.Internal.Query.DelegateEnvelope' is not a field on the target object which is of type 'Db4objects.Db4o.Reflect.Generic.GenericObject'.

Here are the client calls to save, then get:

Server server = new Server() { Name = "AppServerFoo" };
IObjectContainer db = GetDatabase();
db.Store(server);
db.Close();

Here's the only line in the GetDatabase() method:

return Db4oClientServer.OpenClient(Db4oClientServer.NewClientConfiguration(), "DellXps", 8484, "user", "password");

And here's the call to get from the DB:

IObjectContainer db = GetDatabase();
Server testServer = db.Query<Server>(server => server.Name == "AppServerFoo").FirstOrDefault();
db.Close();

What am I missing?


Solution

  • Well a server without a reference the persisted classes is a 'risky' thing. A lot of functionally doesn't work and the error which occur are cryptic. I highly recommend to always reference the assembly with the persisted classes on the server.

    Another tip: Use LINQ instead of native queries. It works better and has less problems.