5

I am trying to deploy Raven DB to my site running .Net 4 in integrated mode (site was previously used to host ASP.Net MVC 3 site.

My configuration file is this:

<appSettings>
    <add key="Raven/DataDir" value="~\App_Data"/>
    <add key="Raven/AnonymousAccess" value="All"/>
  <add key="Raven/Port" value="80"/>
</appSettings>
<system.webServer>
    <handlers>
        <add name="All" path="*" verb="*"
                type="Raven.Web.ForwardToRavenRespondersFactory, Raven.Web"/>
    </handlers>
</system.webServer>

However, the exception I get is this:

**Error FileAccessDenied (JET_errFileAccessDenied, 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.EsentErrorException: Error FileAccessDenied (JET_errFileAccessDenied, 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: 


[EsentErrorException: Error FileAccessDenied (JET_errFileAccessDenied, Cannot access file, the file is locked or in use)]
   Microsoft.Isam.Esent.Interop.Api.Fail(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\ManagedEsent-48322\EsentInterop\Api.cs:2279
   Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE& instance) in C:\Work\ravendb\SharedLibs\Sources\ManagedEsent-48322\EsentInterop\Api.cs:130
   Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\raven\Raven.Storage.Esent\TransactionalStorage.cs:169

[InvalidOperationException: Could not open transactional storage: d:\IIS\domainfolder\ravendb\App_Data\Data]
   Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\raven\Raven.Storage.Esent\TransactionalStorage.cs:182
   Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration) in c:\Builds\raven\Raven.Database\DocumentDatabase.cs:127
   Raven.Web.ForwardToRavenRespondersFactory..cctor() in c:\Builds\raven\Raven.Web\ForwardToRavenRespondersFactory.cs:31

[TypeInitializationException: The type initializer for 'Raven.Web.ForwardToRavenRespondersFactory' threw an exception.]
   Raven.Web.ForwardToRavenRespondersFactory..ctor() +0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +23
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +46
   System.Web.HttpApplication.GetFactory(String type) +81
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184**

I have contacted my host and have confirmation that I have read/write access to App_Data and I have also confirmed this myself by writing some code to create a file there.

My host hinted that my problem might be due to double initialisation of my datastore - whatever that means.

Can any of you point me towards a solution here?

UPDATE 2011-05-18 I am using RavenDB-Build-360 currently available at http://builds.hibernatingrhinos.com/download/2004 . I am using the installation instructions on http://ravendb.net/documentation/docs-deployment-iis for running it on IIS 7.5. But instead of using own local IIS, I am simply copying the content of the /Web-folder to my host . This means the /bin-folder, the web.config and the SilverLight XAP-file. So I am not able to debug my way through anything.

I have not noticed the first line (about WebDAV module) but I will check with my host ASAP.
How does Raven DB rely on this?

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Jesper Lund Stocholm
  • 1,973
  • 2
  • 27
  • 49
  • Does the site have ASP.NET Full Trust Level? I think Raven needs full trust because of Esent being unmanaged code. – nickvane May 17 '11 at 08:40
  • And make sure that you only create 1 instance of DocumentStore and only Initialize it once (in global.asax Application_Start) (hence "the double initialisation of my datastore") – nickvane May 17 '11 at 08:47
  • Hi nickvane, I have not asked for this information, but I'd guess it runs in medium trust. Is the requirement for Raven DB to run in full trust documented anywhere? Also, I am using the build (current: 360) with the precompiled Web-folder so I have not immediate access to global.asax – Jesper Lund Stocholm May 17 '11 at 09:17
  • Hi nickvane, I just now got confirmation that the site runs in full trust, so that should not be the cause of the problem. – Jesper Lund Stocholm May 17 '11 at 09:57
  • If the web-server can write to the folder then it's likely a "double-initialization" issue. Can you debug through your project and see if the RavenDB initialization code is getting called twice? – Matt Warren May 17 '11 at 11:01
  • @jesper-lund-stocholm Can you show us the code where the documentstore is being initialized? The full trust for Esent is not documented, but you can find more info in this thread http://groups.google.com/group/ravendb/browse_thread/thread/9db88d1e07043d02. – nickvane May 17 '11 at 14:12
  • 1
    How are you initializing RavenDB? Is this as a standalone web application? It this as an embedded document store? – Ayende Rahien May 17 '11 at 14:17
  • Hi all, thanks for your input. I have updated the post with some more details of what I am trying to do. – Jesper Lund Stocholm May 18 '11 at 06:48
  • Hi Ayende, It is a simple web application. I just use the pre-compiled assemblies og build 360 and instead of creating a site locally in IIS and pointing it to the /Web-folder, I am x-copying the content of the /Web-folder to my (shared) host. – Jesper Lund Stocholm May 19 '11 at 20:27
  • I ran into this error deploying my MVC app using latest RavenDB. The error message was right, I didn't have write permission in my App_Data. I changed my permissions on my hosting to include the Network Service and Web User to have read/write and that solved the problem. – Steven Hook Jun 24 '11 at 19:00
  • Please answer below and accept your answer, so others will be able to find the solution. – Jerry Bullard Nov 10 '11 at 16:42

2 Answers2

3

i had this exact same problem - my solution was to remove the default App Pool identity from 'ApplicationPoolIdentity' to an administrator account (such as myself for testing purposes). after a restart of the web site, this then worked.

nologo
  • 5,918
  • 3
  • 36
  • 50
  • 1
    This solution worked for me as well although it seems like a bad idea to have to use an Administrator account... I wonder what specific permissions I can apply to the account I used rather than simply making it admin. – t3rse Jan 06 '12 at 04:01
0

I also ran into this problem and was unable to fix it with any of the solutions found on the web.

I ended up going into IIS, right-clicking my web app that uses raven, edit permissions.

Selected the Security tab, clicked NETWORK Service, then checked Full Control. Hit apply, everything started working again.

Bottom line: it turned out to be a permissions issue. I'm unsure why my permissions were changed, as all this was working a few days ago. Perhaps an IIS patch? I don't know. Whatever the case, make sure the Network Service has permission for your web app that uses raven. I gave full control to the Network Service, but you may get away with read/write control.

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212