2011-05-03 30 views
0

我有一個VB.net CF應用程序連接到SQL 2008服務器。 我想實現事務,但是當我在事務開始時破壞我的代碼時,某些讀取查詢無法在表上完成。 例如,從表中選擇所有記錄,其中id爲<> 123 不會返回任何值。 但select * from stock將返回除正在處理的行之外的所有值。隔離級別不能在vb.net連接到SQL 2008 DB

Dim SQLComm As Data.SqlClient.SqlCommand 
Dim myConnString As String = frmConnectionDetails.GetConnectionString 
Dim SQLConn As New SqlConnection(myConnString) 
Dim SQLTrans As SqlTransaction 
SQLConn.Open() 
SQLTrans = SQLConn.BeginTransaction(Data.IsolationLevel.ReadCommitted) 
SQLComm = New SqlCommand 
SQLComm.Connection = SQLConn 
SQLComm.Transaction = SQLTrans 
AddOrUpdateStock(objStock, SQLConn, SQLComm) 
-Break here 

回答

0

一旦你開始一個事務,記錄就會被鎖定,直到提交或回滾才能被訪問。在MSDN上查看這個example

此外,Data.IsolationLevel適用於連接級別。如果你想做髒讀,你應該使用ReadUncommitted