sqlite database is locked on insertion

后端 未结 2 1566
梦毁少年i
梦毁少年i 2021-01-21 08:30

There\'s a simple code

var insert = 
    @\"INSERT INTO [files] (
     [Name],
     [FullName],
     [MD5])
     VALUES (@Name, @FullName, @MD5);\";
using (var c         


        
相关标签:
2条回答
  • 2021-01-21 09:06

    Problem solved. Before this code there was call to SqlCommand.ExecuteReader(). Though connection and command which created this reader were disposed, this reader itself wasn't disposed. After fixing with "using(reader)" connection was closed properly and error above disappeared.

    In total: DataReader can still hold a connection even if connection and SqlCommand were disposed explicitly.

    0 讨论(0)
  • 2021-01-21 09:09

    Your code lacks the call to prepare()

    int i=0;
            try
            {
                Conectar();
                SQLiteCommand comando = new SQLiteCommand(con);
                comando.CommandText = "INSERT INTO EMPRESA (NAME,ESTADO) VALUES (@name, @estado)";
                comando.Parameters.AddWithValue("@name", art.NAME);
                comando.Parameters.AddWithValue("@estado", art.ESTADO);
                comando.Prepare();
                con.Open();
                i = comando.ExecuteNonQuery();
                con.Close();
            }
            catch (SQLiteException ex)
            {
                string a = ex.Message.ToString();   
                throw;
            }
    
            return i;
    
    0 讨论(0)
提交回复
热议问题