每当我调用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();
}
}
你能解释一下我在做什么错吗?
参考方案
尝试移动
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();
}
Sqlite WHERE子句使用参数 - c#尝试使用where子句运行特定查询,这就是我所拥有的。//ID is user input could be anything SqliteParameter Identifier = new SqliteParameter ("@ID", ID); string SQLText = "SELECT Email FROM Cli…
Json到php,json_decode返回NULL - php我正在用PHP进行JSON解析器的一些API,用于存储有关遗产的信息。我在解析时遇到问题,因为它返回的是NULL值而不是数组或对象。简单的JSON代码可以很好地解析,但是可以这样:{"success":true,"totalCount":1,"data":[{"id":99694…
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
SQLAlchemy中的反射不适用于MS SQL Server系统表吗? - python我试图在MS SQL Server数据库中反映系统表:from sqlalchemy import engine, create_engine, MetaData, Table meta = MetaData() url = engine.url.URL( "mssql+pyodbc", username=credentials[…