Erreur de suppression dans une base de données SQLite en C#
Salut à tous, je suis nouveau dans le forum, et j'aimerai bien que quelqu'un puisse m'aider… au fait, je développe en C#, et j'ai un problème avec la base de données créée en SQLite en ce qui concerne la suppression des données dans une table. Lorsque j'essaye de supprimer une donnée, j'ai ce message d'erreur :
Citation:
System.Data.SQLite.SQLiteException (0x80004005) : database is locked
database is locked
à System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
à System.Data.SQLite.SQLiteDataReader.NextResult()
à System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
à System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
à System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
à System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
à ProjetAmba.Form6.SupprimerEleve() dans d:\Mes documents privés\Documents Mont-Amba\ProjetAmba\ProjetAmba\Form6.cs:ligne 108
De fois la suppression marche à merveille après quelques temps de repos, mais cette erreur apparait si souvent. Aidez-moi svp car je suis vraiment bloqué et je ne sais comment m'en sortir… le code source pour la suppression est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public void SupprimerEleve()
{
try
{
SQLiteConnection connexion = new SQLiteConnection("Data Source = GSMA.db; Version = 3;");
connexion.Open();
SQLiteCommand recherche = new SQLiteCommand("SELECT MatriculeEleve FROM Eleve", connexion);
SQLiteDataReader dr = recherche.ExecuteReader();
string matricule = "";
while (dr.Read())
{
if (dr[0].ToString().Equals(txtMatricule.Text))
{
matricule = dr[0].ToString();
break;
}
}
if ((matricule.Equals(txtMatricule.Text)) && (!txtMatricule.Text.Equals(string.Empty)))
{
SQLiteCommand commande = new SQLiteCommand("DELETE FROM Eleve WHERE MatriculeEleve = '" + txtMatricule.Text + "'", connexion);
commande.ExecuteNonQuery();
MessageBox.Show("Elève supprimé !", "Suppression Elève", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (txtMatricule.Text.Equals(string.Empty))
{
MessageBox.Show("Entrez un numéro matricule svp !", "Erreur Matricule", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Ce numéro matricule n'existe pas !", "Matricule inexistant", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
connexion.Close();
}
catch (Exception ex)
{
MessageBox.Show(string.Empty + ex, "Erreur Suppression", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} |
Merci d'avance pour votre aide…