SubSonic 및 SQLite와 트랜잭션을 사용할 때 잠금 예외가 발생합니다. 나는이 스레드를 단일 스레드에서 사용하고 있으며 다른 프로세스가 db에 액세스하지 않으므로 이러한 문제는 실제로 예상하지 못했습니다.단일 스레드에서 트랜잭션을 사용할 때 sqlite 및 SubSonic 잠금 문제
아래 코드를 작성하면 루프 내에서 Save() 호출에 대한 예외가 발생하므로 Save()를 세 번 호출하면 예외가 발생합니다.
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sharedConnectinScope = new SharedDbConnectionScope())
{
SomeDALObject x = new SomeDALObject()
x.Property1 = "blah";
x.Property2 = "blah blah";
x.Save();
foreach (KeyValuePair<string, string> attribute in attributes)
{
AnotherDALObject y = new AnotherDALObject()
y.Property1 = attribute.Key
y.Property2 = attribute.Value
y.Save(); // this is where the exception is raised, on the 2nd time through this loop
}
}
}
나는 위와 같이 문) (사용하거나 그냥 다음 using (TransactionScope ts = new TransactionScope())
이있는 경우 나 데이터베이스 파일은 데이터베이스가
잠겨
메시지와
System.Data.SQLite.SQLiteException
를 얻을 수있는 경우
스택 추적은 다음과 같습니다.
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock)
at System.Data.SQLite.SQLiteConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.SQLite.SQLiteConnection.BeginTransaction()
at System.Data.SQLite.SQLiteEnlistment..ctor(SQLiteConnection cnn, Transaction scope)
at System.Data.SQLite.SQLiteConnection.EnlistTransaction(Transaction transaction)
at System.Data.SQLite.SQLiteConnection.Open()
at SubSonic.SQLiteDataProvider.CreateConnection(String newConnectionString)
at SubSonic.SQLiteDataProvider.CreateConnection()
at SubSonic.SQLiteDataProvider.ExecuteScalar(QueryCommand qry)
at SubSonic.DataService.ExecuteScalar(QueryCommand cmd)
at SubSonic.ActiveRecord`1.Save(String userName)
at SubSonic.ActiveRecord`1.Save()
at (my line of code above).
외부에서 SharedDbConnectionScope를 사용하여 다른 문장으로 중첩 된 구문을 사용하는 경우 "작업이 트랜잭션 상태에 유효하지 않습니다."라는 메시지와 함께 TransactionException
이 표시됩니다.
at System.Transactions.TransactionState.EnlistVolatile(InternalTransaction tx, IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions, Transaction atomicTransaction)
at System.Transactions.Transaction.EnlistVolatile(IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions)
at System.Data.SQLite.SQLiteEnlistment..ctor(SQLiteConnection cnn, Transaction scope)
at System.Data.SQLite.SQLiteConnection.EnlistTransaction(Transaction transaction)
at System.Data.SQLite.SQLiteConnection.Open()
at SubSonic.SQLiteDataProvider.CreateConnection(String newConnectionString)
at SubSonic.SQLiteDataProvider.CreateConnection()
at SubSonic.SQLiteDataProvider.ExecuteScalar(QueryCommand qry)
at SubSonic.DataService.ExecuteScalar(QueryCommand cmd)
at SubSonic.ActiveRecord`1.Save(String userName)
at SubSonic.ActiveRecord`1.Save()
at (my line of code above)
및 내부 예외는 내 생성 DAL 클래스에 사용자 지정 코드가, 또는 내가 될 것이라고 생각할 수있는 영리한 아무것도하지 않는
"트랜잭션 시간 초과"입니다 : 스택 추적입니다 이 원인.
다른 사람이 이와 같은 거래 문제가 발생했거나 누군가 내가 문제를 찾기 시작할 곳을 제안 할 수 있습니까?
감사합니다.
업데이트 : 버전 1.0.61-65 (예 : here)의 릴리스 노트에서 트랜잭션 관련 내용을 언급 했으므로 SubSonic을 최신 버전의 .Net Data Provider와 함께 사용하여 업데이트하는 것이 이러한 문제는 ...
fyi 다른 음속 버전을 보려면 http://github.com/subsonic/SubSonic-2.0/network 또는 여기에서 Paul 's 버전을 다운로드하십시오. http://github.com/PaulS /SubSonic-2.0/commit/55bcb4188c8e7b2a10ae926c8ddf1d00bf03dcf3 (새 버전이 있으면 구식이 될 것입니다). 이 새로운 버전은 동시에 여러 스레드에서 트랜잭션을 실행할 때 AccessViolationExceptions에서 가지고 있었던 다른 잠금 문제를 해결했습니다. 또한 여기에서 System.Data.SQLite 버전 1.0.65.0으로 컴파일하는 것이 좋습니다. http://sourceforge.net/projects/sqlite-dotnet2/ – Rory