0

我有一个连接到 SQL 2008 服务器的 VB.net CF 应用程序。我正在尝试实现事务,但是当我在事务开始时破坏我的代码时,某些读取查询无法在表上完成。例如,从 id <> 123 的表中选择所有记录不会返回任何值。但是 select * from stock 将返回除我正在处理的行之外的所有值。

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
4

1 回答 1

0

一旦开始事务,记录就会被锁定,并且在提交或回滚之前无法访问。在 MSDN 上查看这个示例。

此外,它Data.IsolationLevel适用于连接级别。如果你想做脏读,你应该使用ReadUncommitted

于 2011-06-06T20:54:26.570 回答