I use the same library for our corporate application and, as far as I know, is also documented at http://wp7sqlite.codeplex.com (in the Some section of the Recommendations) , if you close the connection, you will need to recreate it again.
== ADDITIONAL COMMENTS ==
I found out the cause of the error, created a fix and tested it in our application. In short, to migrate the Community.CSharpSqlite library to WP7, the author wrote a FileStream wrapper around WP7 IsolatedStorageFileStream. When db opens, the db file stream opens and reads and closes CSharpSqlite. But the handle to this stream is also stored in the dictionary matching the file path to the stream. When db is opened a second time, the handle to the stream is retrieved, but since it is closed (I assume it has not been tested yet), db does not open.
I will try to incorporate my changes into the wp7sqlite.codeplex.com project, but at the same time, if you have the source code , the following changes to Community.CsharpSqlite.FileStream
change
public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int unused) { IsolatedStorageFileStream handler = null; if (FileStream.HandleTracker.TryGetValue(path, out handler)) { _internal = handler; } else { if (mode == FileMode.Create || mode == FileMode.CreateNew) { _internal = IsolatedStorageIO.Default.CreateFile(path); } else { _internal = IsolatedStorageIO.Default.OpenFile(path, FileMode.OpenOrCreate); } FileStream.HandleTracker.Add(path, _internal); } }
to
public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int unused) { IsolatedStorageFileStream handler = null; if(FileStream.HandleTracker.TryGetValue(path, out handler)) { _internal = handler; if(!_internal.CanRead) { FileStream.HandleTracker.Remove(path); CreateOpenNewFile(path, mode); } } else { CreateOpenNewFile(path, mode); } } private void CreateOpenNewFile(string path, FileMode mode) { if(mode == FileMode.Create || mode == FileMode.CreateNew) { _internal = IsolatedStorageIO.Default.CreateFile(path); } else { try { _internal = IsolatedStorageIO.Default.OpenFile(path, FileMode.OpenOrCreate); } catch(Exception ex) { var v = ex; } } FileStream.HandleTracker.Add(path, _internal); }
This is the first time I'm trying to debug and contribute to an open source project. Any comments or thoughts on these changes would be greatly appreciated.
Alistair.