"Unable to open database file" using SQLite on Windows Phone 7

I am using SQLite for Windows Phone 7 (http://sqlitewindowsphone.codeplex.com/) and I have done every steps from this tutorial (http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx)

Then I try to make some simple application with basic features like select and delete. App is working properly till I want to make one of this operations. After I click select or delete, compiler shows me errors that he is unable to open database file...

I have no idea why?


I used the same Sqlite client, and had the same problem. This problem occurs because the sqlite try to create file in IsolatedFileStorage "DatabaseName.sqlite-journal" and it does not have enough permissions for that. I solved the problem, so that created "DatabaseName.sqlite-journal" before copying database to IsolatedFileStorage. Here's my method that did it:

private void CopyFromContentToStorage(String assemblyName, String dbName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

        string uri = dbName + "-journal";

        store.CreateFile(uri);

        using (Stream input = Application.GetResourceStream(new Uri("/" + assemblyName + ";component/" + dbName,UriKind.Relative)).Stream)
        {
            IsolatedStorageFileStream dest = new IsolatedStorageFileStream(dbName, FileMode.OpenOrCreate, FileAccess.Write, store);
            input.Position = 0;
            CopyStream(input, dest);
            dest.Flush();
            dest.Close();
            dest.Dispose();
        }
    }

it helped me, and worked well.

hope this will help you


Are you sure the file exists? You can check like that:

        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            exists = store.FileExists(DbfileName);
        }
链接地址: http://www.djcxy.com/p/95986.html

上一篇: 如何在windows phone 7中使用sqlite db打开一个表?

下一篇: “无法打开数据库文件”在Windows Phone 7上使用SQLite