title: C# SQLite Database During Update
body: <p>My SQLite query hangs then locks during my ExecuteNonQuery() in WriteToDB() below. It only seems to lock during the UPDATE and has no problem with the INSERT. This is only running in a single thread. When it hangs, I can see the journal being created in the SQLite database directory as if it keeps trying to write. It throws a SQLiteException with ErrorCode=5, ResultCode=Busy.</p>
  
  <pre><code>    public String WriteToDB()
      {
          String retString = "";
  
          //see if account exists with this email
          String sql = "";
          bool aExists = AccountExists();
  
          if (!aExists)
          {
              sql = "INSERT INTO accounts (email, password, proxy, type, description) VALUES ('" + Email + "', '" + Password + "', '" + Proxy + "', 'dev', '" + Description + "');";
              retString = "Added account";
          }
          else
          {
              sql = "UPDATE accounts SET password='" + Password + "', proxy='" + Proxy + "', description='" + Description + "' WHERE (email='" + Email + "' AND type='dev');";
              retString = "Updated account";
          }
  
          using (SQLiteConnection dbconn = new SQLiteConnection("Data Source=" + Form1.DBNAME + ";Version=3;"))
          {
              dbconn.Open();
              using (SQLiteCommand sqlcmd = new SQLiteCommand(sql, dbconn))
              {
                  sqlcmd.ExecuteNonQuery(); //this is where it locks. Only on update.
              }
          }
          return retString;
      }
  
      //Test to see if Email exists as account
      public bool AccountExists()
      {
          int rCount = 0;
          String sql = "SELECT COUNT(email) FROM accounts WHERE email='" + Email + "' AND type='dev';";
          using (SQLiteConnection dbconn = new SQLiteConnection("Data Source=" + Form1.DBNAME + ";Version=3;"))
          {
              dbconn.Open();
              using (SQLiteCommand sqlcmd = new SQLiteCommand(sql, dbconn))
              {
                  rCount = Convert.ToInt32(sqlcmd.ExecuteScalar());
              }
          }
          if (rCount &gt; 0)
              return true;
          return false;
      }
  </code></pre>