Why is my SQLite database considered readonly?

邮差的信 提交于 2021-01-07 04:10:00

问题


I'm getting the following err msg:

...when I try to write to my SQLite database like so:

private async Task InsertMapRecord(string mapName, string mapNotes)
{
    path = folder.Path;
    connStr = string.Format(connStrBase, path);
    try
    {
        SqliteConnection conn = new SqliteConnection(connStr);
        String query = "INSERT INTO CartographerMain " +
            "(MapName, MapNotes) " +
            "VALUES (@MapName, @MapNotes)";

        using (SqliteCommand cmd = new SqliteCommand(query, conn))
        {
            cmd.Parameters.AddWithValue("@MapName", mapName);
            cmd.Parameters.AddWithValue("@MapNotes", mapNotes);
            await conn.OpenAsync();
            int result = await cmd.ExecuteNonQueryAsync();

            if (result < 0)
            {
                MessageDialog dialog = new MessageDialog("Error inserting data into CartographerMain");
                await dialog.ShowAsync();
            }
        }
    }
    catch (SqliteException sqlex)
    {
        string sqlExcMsg = string.Format("{0} Inner Exception: {1} Stack Trace: {2}", sqlex.Message,    sqlex.InnerException, sqlex.StackTrace);
        MessageDialog dialog = new MessageDialog(sqlExcMsg, "InsertMapRecord");
        await dialog.ShowAsync();
    }
}

So, based on some info here, I checked the folder where the app is running. It was marked as readonly, as shown here:

...so I changed it to NOT readonly, applied the change, and saved it thus:

Yet, I still get that same err msg with the above code. What else am I missing?

UPDATE

Answering Selvin's question in the comment below, I am storing the db file like so:

StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
string connStrBase = @"Data source={0}\Cartographer.db";
string connStr = string.Empty;
string path = string.Empty;

. . .

private async Task InsertMapRecord(string mapName, string mapNotes)
{
    path = folder.Path;
    connStr = string.Format(connStrBase, path);
    try
    {
        SqliteConnection conn = new SqliteConnection(connStr);
    . . .

I added the db to the project, set its Copy to Output Directory property to "Copy if newer"

The db file's path is C:\Users\bclay\source\repos\CartographerYou\CartographerYou\Cartographer.db. I manually copied it to there.

来源:https://stackoverflow.com/questions/65380842/why-is-my-sqlite-database-considered-readonly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!