Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When trying to update a table record in SQLite running in UWP enviroment I got the above mentioned error message.

References included:
Microsoft.Data.Sqlite
Microsoft.NETCore.UniversalWindowsPlatform

C# code follows ... any help will be welcome !!!

What I have tried:

private bool SaveConfig()
{
    using (SqliteConnection db = new SqliteConnection("Filename=" + CommonVars.filePath))
    {
        using (SqliteCommand SQLcmd = new SqliteCommand("UPDATE Config SET DBversion = 2 WHERE DBversion = 1", db))
        {
            db.Open();
            try
            {
                SQLcmd.ExecuteNonQuery();
                db.Close();
                return true;
            }
            catch (SqliteException e)
            {
                // Show error and return failed...
                db.Close();
                Console.Write("Error: %s\n", e);
                return false;
            }
        }
    }
}
Posted
Updated 14-May-20 18:43pm

 
Share this answer
 
Comments
Maciej Los 15-Jan-19 2:09am    
5ed!
From what I can see from the limited code provided, You're creating multiple Connections to the DB. For SQLite, this can cause what you are experiencing.

Try setting Pragma journal mode=Wal to allow multiple operations on the DB.

You can read more here: Write-Ahead Logging[^]
 
Share this answer
 
Comments
Maciej Los 15-Jan-19 2:10am    
5ed!
Thank you guys.... problem solved modifing a previous SELECT command as follows:

using (SqliteConnection db = new SqliteConnection("Filename=" + CommonVars.filePath))
{
    using (SqliteCommand SQLcmd = new SqliteCommand())
    {
        SQLcmd.Connection = db;   // Set default connection
        SQLcmd.CommandText = "SELECT * FROM Config";
        db.Open();
        using (SqliteDataReader dr = SQLcmd.ExecuteReader())
        {
 
Share this answer
 
Very silly thing and lost 3 days. It happened as I linked with git. As soon as you able to push then it will update easily.

While pushing make sure it works fine, as some issue arised.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900