2012-10-22 44 views
0

在我的项目中,我使用了如下的sqlite事务。SQLite异常“SQLite错误 - 无事务处于活动状态”

var trans = connection.BeginTransaction(); 

var sql = "delete from table1"; 
connection.ExecuteNonQuery(sql); 

trans.Commit(); // Here, an exception occurred: "No transaction is active". 

什么原因导致问题?
谁能帮帮我?

+0

是的,我使用的是C#。 – bluecart

+0

你能展示更多的代码吗?上面的代码无效(ExecuteNonQuery是SQLiteCommand的方法) – Steve

回答

0

有同样的问题,我只是使用BeginTransaction(IsolationLevel.ReadCommitted);

using (SQLiteConnection connection = new SQLiteConnection(DatabaseConnectionString)) 
{ 
    connection.Open(); 
    connection.BeginTransaction(IsolationLevel.ReadCommitted); 

    SQLiteCommand command = connection.CreateCommand(); 
    command.CommandText = "delete from table1"; 
    command.ExecuteNonQuery(); 
} 
0
using (SQLiteConnection connection = new SQLiteConnection(DatabaseConnectionString)) 
{ 
    connection.Open(); 
    SQLiteCommand command = connection.CreateCommand(); 
    command.CommandText = "delete from table1"; 
    command.ExecuteNonQuery(); 
    command.Dispose(); 
    connection.Close(); 
} 
相关问题