I’m trying to get Community.Csharp working with Windows Phone, I’ve tried using both the version from http://wp7sqlite.codeplex.com/ and compiling the main trunk with the WINDOWS_PHONE flag, but when I run the application on the phone I get an error when trying to execute any queries (but not when opening the database; only on queries): “Unable to open database file”
_conn = new SqliteConnection("Version=3,uri=file:recipes.sqlite");
_conn.Open();
cmd.CommandText = "SELECT * FROM recipes";
SqliteDataReader reader = cmd.ExecuteReader();
Interestingly though, I’m using the following to check for the existence of a table and no exceptions are thrown:
cmd.CommandText = "SELECT * FROM sqlite_master WHERE name='" + tableName + "'";
SqliteDataReader rdr = cmd.ExecuteReader();
exists = rdr.Read();
rdr.Close();
I have a Windows app which uses SQLite, so if I could use SQLite as opposed to Sterling DB or something else, that would save huge amounts of time. The problem I’m having currently is that once I open the database and close it, I cannot re-open it.
I am using the same library for our company’s application and as far as I know, also documented at http://wp7sqlite.codeplex.com (under Some Recommendations ), if you close the connection you’ll need to recreate it again.
== ADDITIONAL COMMENTS ==
I’ve tracked down the cause of the error, created a fix and am testing it in our application. Briefly, in order to port the Community.CSharpSqlite library to WP7, the author wrote a FileStream wrapper around WP7 IsolatedStorageFileStream. When a db is opened, the db file stream is opened and read and closed by CSharpSqlite. But a handle to this stream is also stored in a Dictionary mapping the file path to stream. When a db is opened for a second time, the handle to the stream is retrieved but since it’s closed (I’m assuming, haven’t verified yet) the db fails to open.
I will attempt to get my changes deployed to the wp7sqlite.codeplex.com project, but in the meantime if you have the source code make the following changes to Community.CsharpSqlite.FileStream
change from
to
This is the first time I’m attempting to debug and contribute to an open source project. Any comments or thoughts on these changes will be greatly appreciated.
Alasdair.