简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM