DatabaseFileLockedException 让我抓狂

发布于 2024-09-16 07:16:32 字数 850 浏览 3 评论 0原文

我在这里遵循示例: http://developer.db4o .com/Forums/tabid/98/aft/10114/Default.aspx 使用 HttpModule 通过 db4o 设置我的 MVC2 应用程序。我还打开了一个 LINQPad 实例来在开发时查询数据。 Web 应用程序似乎工作得很好,但 LINQPad 不断收到 DatabaseFileLockedExceptions,直到我关闭 Web 服务器。

正如我所说,我几乎逐字使用 Gamlor 的 HttpModule(唯一的区别是使用 ClientServer 而不是嵌入式),这是我的 LINQPad 代码:

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";

如果 Web 服务器未运行,LINQPad 代码可以正常工作。

我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-09-23 07:16:32

当您打开 db4o 数据库时,它会锁定数据库文件以防止损坏。这意味着当您的服务器运行时,数据库文件被锁定,没有其他进程可以访问它。 (是的,有一种方法可以禁用此功能,但这几乎肯定会损坏数据库)

您的网络服务器是否也在运行客户端服务器模式?如果是这种情况,您可以连接正在运行的 db4o 实例。是不是也可以先尝试连接,如果失败就直接打开服务器?

如果您仅在 ASP.NET 应用程序中使用嵌入式客户端服务器,则可以出于调试目的将其更改为真正的客户端服务器。 ASP.NET 仅使用嵌入式客户端。但它可以让您与 LINQ-Pad 连接。

评论的答案:

您需要打开 完全服务器,支持通过网络连接的客户端。例如:

// 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
     }

}

然后在 LINQPad 中:

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

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文