2012-04-24 221 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