우리가 개발중인 응용 프로그램의 경우 표에서 행 n 행을 읽고 도메인 특정 기준에 따라 행을 선택적으로 업데이트해야합니다. 이 작업을 수행하는 동안 데이터베이스의 다른 모든 사용자는 잘못된 읽기를 방지하기 위해 잠글 필요가 있습니다.SQLite 트랜잭션이 적용되지 않습니다.
트랜잭션을 시작하고 행을 읽은 다음 레코드 세트를 반복하는 동안 업데이트 명령문 문자열을 작성합니다. 레코드 세트를 읽은 후에 레코드 세트를 닫고 업데이트를 실행합니다. 이 시점에서 나는 트랜잭션을 커미트하지만 업데이트는 데이터베이스에서 수행되지 않습니다.
private static SQLiteConnection OpenNewConnection()
{
try
{
SQLiteConnection conn = new SQLiteConnection();
conn.ConnectionString = ConnectionString;//System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
conn.Open();
return conn;
}
catch (SQLiteException e)
{
LogEvent("Exception raised when opening connection to [" + ConnectionString + "]. Exception Message " + e.Message);
throw e;
}
}
SQLiteConnection conn = OpenNewConnection();
SQLiteCommand command = new SQLiteCommand(conn);
SQLiteTransaction transaction = conn.BeginTransaction();
// Also fails transaction = conn.BeginTransaction();
transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted);
command.CommandType = CommandType.Text;
command.Transaction = transaction;
command.Connection = conn;
try
{
string sql = "select * From X Where Y;";
command.CommandText = sql;
SQLiteDataReader ranges;
ranges = command.ExecuteReader();
sql = string.Empty;
ArrayList ret = new ArrayList();
while (MemberVariable > 0 && ranges.Read())
{
// Domain stuff
sql += "Update X Set Z = 'foo' Where Y;";
}
ranges.Close();
command.CommandText = sql;
command.ExecuteNonQuery();
// UPDATES NOT BEING APPLIED
transaction.Commit();
return ret;
}
catch (Exception ex)
{
transaction.Rollback();
throw;
}
finally
{
transaction.Dispose();
command.Dispose();
conn.Close();
}
return null;
트랜잭션을 제거하면 모든 것이 예상대로 작동합니다. "Domain stuff"은 도메인 지정이며 레코드 세트의 값을 읽는 것 이외의 다른 값은 데이터베이스에 액세스하지 않습니다. 나는 한 걸음 잊었 니?
제프 앳 우드 (Jeff Atwood)가 이런 종류의 디자인에 대해 불만을 품고 있음에도 불구하고이 사이트에서 스크롤 막대를 사용한다는 것이 얼마나 이상한 일인지 알아 챘습니까? – marr75