You are here: Client-Server

Client-Server

db4o's is an embedded database which usually runs in process. Nevertheless db4o also supports a client server setup. There's no ready to use db4o server, instead you embedded the db4o server in a regular application. This gives you full how you want to run the db4o server.

In order to use the db4o client server mode you need to include the Db4objects.Db4o.CS.dll-assembly in your project. See "Dependency Overview"

Start The Server

You start the server by creating a object server instance with the client server factory. Pass the database file path and the port to the factory. After that you need to specify a user-name and password which clients can use to login to this server. You can add multiple users by calling the grant access method multiple times.

using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", 8080))
{
    server.GrantAccess("user", "password");

    // Let the server run.
    LetServerRun();
}
ServerExample.cs: Start a db4o server
Using server As IObjectServer = Db4oClientServer.OpenServer("database.db4o", 8080)
    server.GrantAccess("user", "password")

    ' Let the server run.
    LetServerRun()
End  Using
ServerExample.vb: Start a db4o server

Connect To The Server

After the server is up an running you can connect to it. Pass the URL, port, user name and password to the client server factory. This will return a client object container. After that the container is ready to use.

using (IObjectContainer container
    = Db4oClientServer.OpenClient("localhost", 8080, "user", "password"))
{
    // Your operations
}
Db4oClientExample.cs: Connect to the server
' Your operations
Using container As IObjectContainer = Db4oClientServer.OpenClient("localhost", 8080, "user", "password")
End  Using
Db4oClientExample.vb: Connect to the server