2012-04-24 181 views
10

我有一个ASP.Net MVC 3应用程序,我已经开发了使用RavenDB嵌入为一体的综合后备存储的数据,我用this教程作为入门创建与RavenDB的MVC应用程序中嵌入的基础。我已经能够到我的开发PC上运行良好,但是当是时候将其部署到我们的Windows Server 2003 Web服务器运行IIS6把它扔到了以下错误:RavenDB部署问题

Cannot access file, the file is locked or in use Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Isam.Esent.Interop.EsentFileAccessDeniedException: Cannot access file, the file is locked or in use

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[EsentFileAccessDeniedException: Cannot access file, the file is locked or in use] Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:2736 Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:207

[InvalidOperationException: Could not open transactional storage: C:\inetpub\wwwroot\MyApp\App_Data\Database\RavenDB\Data]
Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:222 Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:185
Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal() in c:\Builds\RavenDB-Stable\Raven.Client.Embedded\EmbeddableDocumentStore.cs:143 Raven.Client.Document.DocumentStore.Initialize() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\DocumentStore.cs:496 MyApp.CompositionRoot.CreateControllerFactory() in ...\MyApp\CompositionRoot.cs:36 MyApp.CompositionRoot..ctor() in ..\MyApp\CompositionRoot.cs:17
MyApp.MvcApplication.Application_Start() in ...MyApp\Global.asax.cs:38

[HttpException (0x80004005): Could not open transactional storage: C:\inetpub\wwwroot\MyApp\App_Data\Database\RavenDB\Data]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3985477
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375

[HttpException (0x80004005): Could not open transactional storage: C:\inetpub\wwwroot\MyApp\App_Data\Database\RavenDB\Data]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11524352 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4782309

错误的源引用的CompositionRoot.cs类是Embeddable Document Store的初始化时。

private static IControllerFactory CreateControllerFactory() 
{ 
    var cacheRepository = new EmbeddableDocumentStore(); 
    cacheRepository.ConnectionStringName = "RavenDB"; 

    #if DEBUG 
     cacheRepository.UseEmbeddedHttpServer = true; 
    #endif 

    Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080); 
    cacheRepository.Initialize(); //Source of Error 
    var controllerFactory = new TDRControllerFactory(cacheRepository); 
    return controllerFactory; 
} 

为什么这只发生在Web服务器上,而不是在我的开发PC上?我不确定究竟是什么原因。任何帮助表示赞赏。

+0

听起来像在IIS下运行的经典权限问题。不熟悉RavenDB嵌入式,但我会将其移动到\ webroot之外,并将IIS用户授予该路径。 – kenny 2012-04-25 02:03:21

+0

RavenDB已经作为服务或从命令行运行? – wal 2012-04-25 06:36:03

回答

15

事实证明,这是一个权限问题,我给IIS_IUSRS组修改和写入权限在我的应用程序文件夹的根目录,这给了它,它需要正确初始化数据库的权限。根目录中可能有一个特定的文件夹,它需要修改/写入权限(在我的情况下,可能是App_Data文件夹,因为这是我实例化RavenDB实例的地方)。我将不得不测试,因为我不希望任何用户拥有对整个应用程序文件夹的修改/写入权限。

4

你需要确保你的CreateControllerFactory将只运行一次,即使在应用程序启动时的并发请求的面貌。

+0

谢谢Ayende,错误原来是一个权限问题。我给我的应用程序的根文件夹修改和写入访问IIS_IUSRS组,并允许数据库正确初始化。我会记住你的答案,以防万一问题再次出现。在RavenDB上做了非常棒的工作,这是我们对非关系数据库的第一次尝试,所以我们很想看看它是如何工作的。 – kingrichard2005 2012-04-25 16:42:40