RavenDB - EmbeddableDocumentStore已经处理或NRE

时间:2014-04-28 15:27:28

标签: asp.net-mvc-4 ravendb nullreferenceexception shared-hosting objectdisposedexception

这个问题是关于在ASP.Net MVC应用程序的生命周期中创建Raven文档存储的单个实例,然后在每个请求中使用新的IDocumentSession来为客户端提供服务。我相信已遵循http://ravendb.net/kb/3/using-ravendb-in-an-asp-net-mvc-website中描述的建议程序,我在部署网站后仍然遇到错误。

我的代码如下所示。 HepApp类包含文档存储,并由应用程序引用:

internal class HepApp
{
    internal static readonly Object padlock = new object();
    private static IDocumentStore _DB;

    internal IDocumentStore DB
    {
        get
        {
            if (_DB == null)
            {
                lock (padlock)
                {
                    if (_DB == null)
                    {
                        _DB = new EmbeddableDocumentStore().Initialize();
                        return _DB;
                    }
                }                    
            }
            return _DB;
        }
    }

    public IDocumentSession GetSession()
    {
        return DB.OpenSession();
    }
}

我的MVC控制器:

public class HomeController : Controller
{
    IDocumentSession RavenSession;

    public HomeController()
    {
    }

    protected void Init()
    {
        RavenSession = MvcApplication.HepApp.GetSession();
    }

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        base.OnActionExecuting(filterContext);
        Init();
    }

应用程序类Global.asax绑定到:

public class MvcApplication : System.Web.HttpApplication
{
    static readonly Object padlock = new object();
    static HepApp _HepApp;

    internal static HepApp HepApp
    {
        get
        {
            if(_HepApp == null)
            {
                lock(padlock)
                {
                    if(_HepApp == null)
                    {
                        _HepApp = new HepApp();
                    }
                }
            }

            return _HepApp;
        }
    }

当应用程序启动时,应该初始化文档存储,并在应用程序的剩余生命周期内生效。对于每个请求,都会创建一个新的Session对象。至少,这是个想法。而是在OnActionExecuting中出现空引用错误(虽然我怀疑HomeController.Init方法但它不会出现在堆栈上)或者已经处理了EmbeddableDocumentStore对象。令人困惑的是,这些错误只会在应用程序运行一段时间后出现,这可能表明它是一个应用程序池回收问题

编辑: 错误有所不同,但似乎都表明数据库存储的实例化存在问题:

  

[EsentFileAccessDeniedException:无法访问文件,文件被锁定或正在使用]   [InvalidOperationException:无法写入位置:\ 192.168.0.100 \ localuser \ x \ App_Data / Raven。确保您对此路径具有读/写权限。]

     

System.InvalidOperationException:无法写入位置:\ 192.168.0.100 \ localuser \ x \ App_Data / Raven。确保您具有此路径的读/写权限。 ---> Microsoft.Isam.Esent.Interop.EsentFileAccessDeniedException:无法访问文件,文件被锁定或正在使用中      在Microsoft.Isam.Esent.Interop.Api.Check(Int32 err)      在Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE& instance)      在Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection 1 documentCodecs) --- End of inner exception stack trace --- at Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator, OrderedPartCollection 1 documentCodecs)      在Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration配置,TransportState transportState)      在Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal()      在Raven.Client.Document.DocumentStore.Initialize()      在HEPlaceHolder.HepApp.get_DB()的e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Logic \ HepApp.cs:第27行      在e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Controllers \ HomeController.cs中的HEPlaceHolder.Controllers.HomeController.OnActionExecuting(ActionExecutingContext filterContext):第31行      在System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)      at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex)      在System.Web.Mvc.Async.AsyncControllerActionInvoker。<> c__DisplayClass33.b__31(AsyncCallback asyncCallback,Object asyncState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext,IList 1 filters, ActionDescriptor actionDescriptor, IDictionary 2个参数,AsyncCallback回调,对象状态)      在System.Web.Mvc.Async.AsyncControllerActionInvoker。<> c__DisplayClass21.b__19(AsyncCallback asyncCallback,Object asyncState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,String actionName,AsyncCallback callback,Object state)      在System.Web.Mvc.Controller.b__1c(AsyncCallback asyncCallback,Object asyncState,ExecuteCoreState innerState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback回调,对象状态)      在System.Web.Mvc.Controller.b__14(AsyncCallback asyncCallback,Object callbackState,Controller controller)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)      在System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)      在System.Web.Mvc.MvcHandler.b__4(AsyncCallback asyncCallback,Object asyncState,ProcessRequestState innerState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)      在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback回调,对象状态)      在System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object extraData)      在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()      在System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

     

[ObjectDisposedException:文档存储已被释放且无法使用   对象名称:' EmbeddableDocumentStore'。]      Raven.Client.DocumentStoreBase.EnsureNotClosed()+ 82   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback,Object state,Int32 timeout)+128

     

[NullReferenceException:对象引用未设置为对象的实例。]      e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Controllers \ HomeController.cs中的HEPlaceHolder.Controllers.HomeController.OnActionExecuting(ActionExecutingContext filterContext):31   System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)+10

     

System.InvalidOperationException:无法打开事务存储:\ 192.168.0.100 \ localuser \ x \ App_Data / Raven \ Data ---> Microsoft.Isam.Esent.Interop.EsentTempPathInUseException:另一个数据库实例已使用的临时路径      在Microsoft.Isam.Esent.Interop.Api.Check(Int32 err)      在Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE& instance)      在Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection 1 documentCodecs) --- End of inner exception stack trace --- at Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator, OrderedPartCollection 1 documentCodecs)      在Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration配置,TransportState transportState)      在Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal()      在Raven.Client.Document.DocumentStore.Initialize()      在HEPlaceHolder.HepApp.get_DB()的e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Logic \ HepApp.cs:第27行      在e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Controllers \ HomeController.cs中的HEPlaceHolder.Controllers.HomeController.OnActionExecuting(ActionExecutingContext filterContext):第31行      在System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)      at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex)      在System.Web.Mvc.Async.AsyncControllerActionInvoker。<> c__DisplayClass33.b__31(AsyncCallback asyncCallback,Object asyncState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext,IList 1 filters, ActionDescriptor actionDescriptor, IDictionary 2个参数,AsyncCallback回调,对象状态)      在System.Web.Mvc.Async.AsyncControllerActionInvoker。<> c__DisplayClass21.b__19(AsyncCallback asyncCallback,Object asyncState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,String actionName,AsyncCallback callback,Object state)      在System.Web.Mvc.Controller.b__1c(AsyncCallback asyncCallback,Object asyncState,ExecuteCoreState innerState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback回调,对象状态)      在System.Web.Mvc.Controller.b__14(AsyncCallback asyncCallback,Object callbackState,Controller controller)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)      在System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)      在System.Web.Mvc.MvcHandler.b__4(AsyncCallback asyncCallback,Object asyncState,ProcessRequestState innerState)      在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.Begin(AsyncCallback回调,对象状态,Int32超时)      在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)      在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback回调,对象状态)      在System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object extraData)      在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()      在System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

编辑: 每当使用调整版本更新bin文件夹来调试问题时,站点最初都会运行正常,大概是因为应用程序被重置。

0 个答案:

没有答案