views:

26

answers:

1

I am following the example here: http://developer.db4o.com/Forums/tabid/98/aft/10114/Default.aspx to setup my MVC2 app with db4o using an HttpModule. I also have a LINQPad instance open to query the data as I develop. The web app seems to work like a charm, but LINQPad keeps getting DatabaseFileLockedExceptions until I close down the web server.

As I said, I'm using the HttpModule from Gamlor practically verbatim (using ClientServer instead of embedded is the only difference), and here's my LINQPad code:

01  void Main() 
02  { 
03      using(var server = Db4oClientServer.OpenServer(db4opath, 0)) 
04      { 
05          using(var db = server.OpenClient()){ 
06              var result = (from Object o in db select o); 
07              result.Dump(); 
08          } 
09      } 
10  } 
11    
12  private string db4opath = @"C:\blah\blah\blah\blah.db4o";

The LINQPad code works fine if the web server isn't running.

What am I doing wrong?

+1  A: 

When you open the db4o database it locks the database-file to prevent corruption. This means while your server is running, the database file is locked and no other process can access it. (Yes there's a way to disable this, but that will almost certainly corrupt the database)

Is you're webserver also running client server mode? If thats the case you could connect the the running db4o-instance. You also can first try to connect and only if you fail directly open the server?

If you're only using the embedded-client server in your ASP.NET application, you could change that for debugging-purposes to real client server. The ASP.NET only uses the embedded clients. But it lets you connect with LINQ-Pad.

Answer for the comment:

You need to open a fully server, which supports clients which connect over the network. For example:

// in your application
int PortNumber = 8888;
using(var server = Db4oClientServer.OpenServer("database.db4",PortNumber))
{
     server.GrantAccess("debug-user","debug-pwd");

     // application uses embedded client:
     using(var container = server.OpenClient())
     {
          // your application does stuff
     }

}

And then in LINQPad:

using(var client = Db4oClientServer.OpenClient("localhost",8888,"debug-user","debug-pwd"))
{
     // do stuff

}
Gamlor
I'm using client/server in both the web app and LINQPad. How can I connect to the db4o running instance from LINQPad if I don't have a reference to the server object?
mgroves