Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1004489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:08:33+00:00 2026-05-16T08:08:33+00:00

I’m building a small web application with ASP.NET MVC 2, using db4o as a

  • 0

I’m building a small web application with ASP.NET MVC 2, using db4o as a datastore.

I have added an HttpModule—as per the example here—to give the application access to the db4o database, and everything is working perfectly on my development machine under the VS2008 ASP.NET Development Server.

However, when I deploy the app to my web host and try to access it, I get a DatabaseFileLockedException at the line where the HttpModule tries to open the database file. But there should be nothing else accessing the file; indeed on first run of the app it will only just have been created when this exception gets thrown.

The web host’s servers are running IIS 7 on Windows Server 2008, and the application is running under Full Trust. It is a sub-application, in case that makes any difference.

I can’t work out why this error is occurring on the live server, but not locally on my development server. Can anyone help me out or suggest what I should do next?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:08:33+00:00Added an answer on May 16, 2026 at 8:08 am

    That’s a mistake in the example-code. It assumes that the HttpModule.Init is only called once, which isn’t necessarily true. Depending how your application is configured, it can be called multiple times. To fix this, check in the HttpModule-Handler if the instance is already there:

    using System;
    using System.Configuration;
    using System.Web;
    using Db4objects.Db4o;
    
    namespace Db4oDoc.WebApp.Infrastructure
    {
        public class Db4oProvider : IHttpModule
        {
            private const string DataBaseInstance = "db4o-database-instance";
            private const string SessionKey = "db4o-session";
    
            // #example: open database when the application starts
            public void Init(HttpApplication context)
            {
                if (null==HttpContext.Current.Application[DataBaseInstance])
                {
                    HttpContext.Current.Application[DataBaseInstance] = OpenDatabase();
                }
                RegisterSessionCreation(context);
            }
    
            private IEmbeddedObjectContainer OpenDatabase()
            {
                string relativePath = ConfigurationSettings.AppSettings["DatabaseFileName"];
                string filePath = HttpContext.Current.Server.MapPath(relativePath);
                return Db4oEmbedded.OpenFile(filePath);
            }
            // #end example
    
            // #example: close the database when the application shuts down
            public void Dispose()
            {
                IDisposable toDispose = HttpContext.Current.Application[DataBaseInstance] as IDisposable;
                if (null != toDispose)
                {
                    toDispose.Dispose();
                }
            }
            // #end example
    
            // #example: provide access to the database
            public static IObjectContainer Database
            {
                get { return (IObjectContainer)HttpContext.Current.Items[SessionKey]; }
            }
            // #end example
    
            // #example: A object container per request
            private void RegisterSessionCreation(HttpApplication httpApplication)
            {
                httpApplication.BeginRequest += OpenSession;
                httpApplication.EndRequest += CloseSession;
            }
    
            private void OpenSession(object sender, EventArgs e)
            {
                IEmbeddedObjectContainer container =
                    (IEmbeddedObjectContainer)HttpContext.Current.Application[DataBaseInstance];
                IObjectContainer session = container.OpenSession();
                HttpContext.Current.Items[SessionKey] = session;
            }
    
            private void CloseSession(object sender, EventArgs e)
            {
                if (HttpContext.Current.Items[SessionKey] != null)
                {
                    IObjectContainer session = (IObjectContainer)HttpContext.Current.Items[SessionKey];
                    session.Dispose();
                }
            }
            // #end example
        }
    }
    

    As alternative you could use the Application_Start from the Global.apsx, which is called only once for sure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.