title: Sqlite database lock error using c# application
body: <p>I n my c# application , i am using sqlite as backend. when i perform simple insert query it takes me too long and end up with database is locked message..I deployed my application in stage server and performing the action remotely..Below is my code please help.</p>
  
  <pre><code>String sqlExpr = "INSERT INTO item (id, typeid, ownerid, created, modifiedby, modified,active,imageuploaded,logouploaded,language_item) VALUES (@Id,@type_TypeId ,@db_currentUser,@dates,@db_id ,@modified,@active_status,@image,@logo,@language)";
  
                      //using (SQLiteCommand _insertItem = new SQLiteCommand())
                      //{
                      SQLiteCommand _insertItem = new SQLiteCommand();
                          _insertItem.CommandText = sqlExpr;
                          _insertItem.Parameters.AddWithValue("@Id", Id);
                          _insertItem.Parameters.AddWithValue("@type_TypeId", type.TypeId);
                          _insertItem.Parameters.AddWithValue("@db_currentUser", db.currentUser.id);
                          _insertItem.Parameters.AddWithValue("@dates", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                          _insertItem.Parameters.AddWithValue("@db_id", db.currentUser.id);
                          _insertItem.Parameters.AddWithValue("@modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                          _insertItem.Parameters.AddWithValue("@active_status", active_status);
                          _insertItem.Parameters.AddWithValue("@image", "false");
                          _insertItem.Parameters.AddWithValue("@logo", "false");
                          _insertItem.Parameters.AddWithValue("@language", language);
                          rowsAffected = db.ExecuteNonQuerySQL(_insertItem);
                          db.Close();
  
  
   public int ExecuteNonQuerySQL(SQLiteCommand cmd)
          {
              int ireturn = 0;
  
              if (conn.State != ConnectionState.Open)//the connection is individual for each session so no need of lock .added the code on 2011-11-08 by Sangeetha
                  Open(DataFile);
              //SQLiteConnection C = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
  
              using (SQLiteTransaction dbtrans = conn.BeginTransaction(IsolationLevel.ReadCommitted))
              {
                  using (SQLiteCommand cmd1 = (SQLiteCommand)cmd.Clone())
                  {
  
                      cmd.Dispose();
                      cmd1.Connection = conn;
                      cmd1.Transaction = dbtrans;
                      ireturn = cmd1.ExecuteNonQuery();
                      dbtrans.Commit();
                      cmd1.Dispose();
                  }
              }
  
  
              return ireturn;
          }
  </code></pre>
  
  <p>Thank you</p>