开发者

Isolation level not working in vb.net connecting to a SQL 2008 DB

开发者 https://www.devze.com 2023-03-02 05:09 出处:网络
I have a VB.net CF app connecting to a SQL 2008 server. I\'m trying to implement transactions but when i break my code at the start of a transaction certain read queries cannot be done on the table.

I have a VB.net CF app connecting to a SQL 2008 server. I'm trying to implement transactions but when i break my code at the start of a transaction certain read queries cannot be done on the table. For instance selecting all records from the table where id <> 123 Won't return any values. But select * from stock will return all values except for the row I'm working on.

开发者_运维问答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


Once you start a transaction, the record becomes locked and can't be accessed until either a commit or rollback. Take a look at this example over at MSDN.

Also, the Data.IsolationLevel applies at the connection level. If you want to do dirty reads you should be using ReadUncommitted

0

精彩评论

暂无评论...
验证码 换一张
取 消