这个问题是关于在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的Microsoft.Isam.Esent.Interop.Api.Check(Int32错误)中被锁定或正在使用 . Api.JetInit(JET_INSTANCE&instance)在Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection1 documentCodecs)---内部异常堆栈跟踪结束---在Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator, OrderedPartCollection1 documentCodecs)位于Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal()的Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration配置,TransportState transportState),位于HEPlaceHolder.HepApp.get_DB的Raven.Client.Document.DocumentStore.Initialize() )在e:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Logic \ HepApp.cs:第27行,位于e:\ projects \ HEPlaceHolder \ HEPlaceH中的HEPlaceHolder.Controllers.HomeController.OnActionExecuting(ActionExecutingContext filterContext) old \ Controllers \ HomeController.cs:System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)第31行,位于System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) System.Web.Mvc上System.Web.Mvc.Async.AsyncControllerActionInvoker . <> c__DisplayClass33.b__31(AsyncCallback asyncCallback,Object asyncState)的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallBeginDelegate(AsyncCallback回调,Object callbackState) System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext,IList1过滤器,ActionDescriptor actionDescriptor,IDictionary2参数,AsyncCallback回调,对象状态)中的.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)at at System.Web.Mvc.Async.AsyncControllerActionInvoker . <> c__DisplayClass21.b__ System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,系统中的System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,String actionName,AsyncCallback回调,对象状态)处的系统上的System.Web.Mvc.Controller.b__1c(AsyncCallback asyncCallback,Object asyncState,ExecuteCoreState innerState)的Int32超时) System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin中的.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback,Object callbackState)(AsyncCallback回调,对象状态,的Int32超时)在System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback的回调,对象状态)在System.Web.Mvc.Controller.b__14(的AsyncCallback的AsyncCallback,在System.Web.Mvc对象callbackState,控制器控制器) . System.Web.Mvc.Controller.BeginExecute(RequestContext)上System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)的Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback回调,Object callbackState) System.Web.Mvc.MvcHandler.b__4上的System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)中的requestContext,AsyncCallback回调,对象状态(AsyncCallback)的AsyncCallback,在System.Web.Mvc.Async.Asyn对象asyncState,ProcessRequestState innerState)在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback的回调,对象callbackState) System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback)上的System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)中的cResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时) System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute(System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object extraData)上的回调,对象状态) )在System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)[ObjectDisposedException:文档存储已经被处理,不能使用对象名称:'EmbeddableDocumentStore' . ] Raven.Client.DocumentStoreBase.EnsureNotClosed()82系统 . Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback回调,对象状态,Int32超时)128 [NullReferenceException:Object reference未设置为对象的实例 . ]在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:Temp path已经在Microsoft.Isam.Esent.Interop.Api.Check(的Int32 ERR)在Microsoft.Isam.Esent.Interop.Api.JetInit在Raven.Storage.Esent.TransactionalStorage.Initialize(JET_INSTANCE&实例)(IUuidGenerator由另一个数据库实例uuidGenerator,OrderedPartCollection1 documentCodecs)---内部异常堆栈跟踪的末尾在Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection1 documentCodecs)在Raven.Database.DocumentDa tabase..ctor(InMemoryRavenConfiguration配置,TransportState transportState)位于Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal()中的Raven.Client.Document.DocumentStore.Initialize()位于e:\ projects \ HEPlaceHolder中的HEPlaceHolder.HepApp.get_DB() \ HEPlaceHolder \ Logic \ HepApp.cs:位于E:\ projects \ HEPlaceHolder \ HEPlaceHolder \ Controllers \ HomeController.cs中的HEPlaceHolder.Controllers.HomeController.OnActionExecuting(ActionExecutingContext filterContext)第27行:System.Web.Mvc.Controller第31行 . System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(的Int32 filterIndex)在System.Web.Mvc.Async.AsyncControllerActionInvoker . <> c__DisplayClass33.b__31(的AsyncCallback的AsyncCallback System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallBeginDelegate,AsyncCallback callback,Object callbackSta,Object Object asyncState) te)System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)在System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext,IList1过滤器,ActionDescriptor actionDescriptor,IDictionary2参数) System.Web.Mvc.Async.AsyncControllerActionInvoker中的AsyncCallback回调,对象状态 . <> c__DisplayClass21.b__19(AsyncCallback asyncCallback,Object asyncState)at atSystem.Web.Mvc上System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallBeginDelegate(AsyncCallback回调,Object callbackState) System.Web.Mvc.Async.AsyncResultWrapper上的System.Web.Mvc.Controller.b__1c(AsyncCallback asyncCallback,Object asyncState,ExecuteCoreState innerState)中的.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext,String actionName,AsyncCallback callback,Object state) . System.Web.Mvc.Controller.BeginExecuteCore上的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)中的WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback回调,Object callbackState)(AsyncCallback回调,对象状态) )System.Web.Mvc.Async.Async上的System.Web.Mvc.Controller.b__14(AsyncCallback asyncCallback,Object callbackState,Controller controller) System.Web.Mvc.Controller.BeginExecute的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)中的ResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback回调,对象callbackState)(RequestContext requestContext, System.Web.Mvc.MvcHandler.b__4上的System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext,AsyncCallback callback,Object state)中的AsyncCallback回调,Object状态(AsyncCallback asyncCallback,在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback回调,对象状态,Int32超时)的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback回调,对象callbackState)上的Object asyncState,ProcessRequestState innerState) )System.Web.Mvc.MvcHandler.BeginPro上的System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态) System.Web.HttpApplication.CallHandlerExecutionStep.System.Web上的System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext上下文,AsyncCallback cb,Object extraData)中的cessRequest(HttpContext httpContext,AsyncCallback回调,Object状态) . System.Web.HttpApplication.ExecuteStep中的HttpApplication.IExecutionStep.Execute()(IExecutionStep step,Boolean&completedSynchronously)
编辑:每当使用调整版本更新bin文件夹来调试问题时,网站最初运行正常,大概是因为应用程序被重置 .