2012-10-22 3 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(); 
} 
관련 문제