每当我调用test()方法时 代码运行,直到它到达Messagebox.show() 当我尝试插入“vandute”表时,我收到错误“DATABASE IS LOCKED”
private void test()
{
int z;
SQLiteConnection dbcon = new SQLiteConnection("Data Source=stefanauto.psa;Version=3;");
dbcon.Open();
using (SQLiteCommand sql = new SQLiteCommand(dbcon))
{
sql.CommandText = "select ID from clienti where CNP='" + cnp.Text + "'";
z = Convert.ToInt32(sql.ExecuteScalar());
MessageBox.Show(z.ToString());//The error begins after this line
sql.CommandText = "insert into vandute(ID_MASINA,ID_CLIENT)values(1,2)";//Id_MASINA,ID-CLIENT ARE integers
sql.ExecuteNonQuery();
}
}
请你解释一下我做错了什么?
答案 0 :(得分:1)
尝试移动
dbcon.Open();
在using
区块内。像
using (SQLiteConnection c = new SQLiteConnection("Data Source=stefanauto.psa;Version=3;"))
{
c.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, c))
{
//your code
}
}
或尝试明确处理您的连接
public void DisposeConnection()
{
SQLiteConnection.Dispose();
SQLiteCommand.Dispose();
GC.Collect();
}
答案 1 :(得分:1)
尝试创建新命令;
node_modules/electron-prebuilt/dist/electron .