This project is read-only.

filestreams not closed when exception in Odb constructor


When an exception is thrown during the construction of an Odb instance, the filestream is not closed. This then prevents deleting or moving the file as a corrective action.

This is a quick fix for the problem. No idea if it's the best way to handle it.
--- a/src/Core/Engine/StorageEngine.cs  Thu Aug 08 18:33:52 2013 -0700
+++ b/src/Core/Engine/StorageEngine.cs  Thu Aug 08 18:34:45 2013 -0700
@@ -113,6 +113,8 @@
+                _session.Close();
+                _objectWriter.Close();
                 if (parameters is FileIdentification)
Note that IDisposable does not help.
using (var odb = OdbFactory.Open("test.db"))
The exception is thrown during the call to OdbFactory.Open(), so using(){} does not call IDispose -- there isn't even an available instance for using(){} to call Dispose() on because .Open() did not return a value.


JaronRH wrote Oct 2, 2014 at 8:28 PM

I'm using's trial hosting with NDatabase and I'm noticing that there is an issue with whatever they are doing overnight (which I'm guessing causes the application pool to recycle). I've noticed that NDatabase will hang until I force a reload by renaming the NDatabase.dll and web.config files.

Anyway, I downloaded the source to look for issues and can confirm the above comments. You can even modify the code to throw an exception during StorageEngine's constructor and any following requests will hang until the process is restarted.

I made a similar change as above:
                if (ObjectReader != null) 
                if (_objectWriter != null) 
                if (_session != null) 
I don't know if it will fix my issue or not but it definitely freed up the file resource so that a subsequent call could access the db file.