jeudi 28 avril 2016

updating database from other form- error database is locked

I created an app like a quizz.. when I try to update the bestscore to database and to the menu form (which is a parent of the form I`m into) I got this error:

An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll   Additional information: database is locked database is locked

The Menu (parent) code:

public void update_score(string materie,int score)
   {           

      if (con_opened == false)
      {
          con = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");//Version=3;
          con_opened = true;
          con.Open();
      }

      string sql = "UPDATE bestscore SET bestscore=<score> WHERE materie LIKE \'<materie>'";
      sql = sql.Replace("<materie>",materie);
      sql = sql.Replace("<score>", score.ToString());
      SQLiteCommand command = new SQLiteCommand(sql, con);
      command.ExecuteNonQuery();
      command.Dispose();
      db_inchide();
      MessageBox.Show("am facut update");
  }
  void db_inchide()
  {
     if (con_opened == true)
        con.Close();
     con_opened = false;

  }
  public void check_score(string materie,int score)
  {
      if(materie=="informatica" && score>bs_info)
      {
          bs_info = score;
          update_score(materie, bs_info);
      }
      else
          if(materie=="literatura" && score>bs_lit)
          {
              bs_lit = score;
              update_score(materie, bs_lit);
          }
  }

The function I use in the "quizz" Form:

string mesaj = "Felicitari! Ai obtinut " + score.ToString() + " puncte! :-)";
Meniu fmenu=new Meniu();
fmenu.check_score(materie, score);
fmenu.Close();               

I uploaded the entire app: http://ift.tt/1QDC7Vy

Thank you!

Aucun commentaire:

Enregistrer un commentaire