隔离级别在连接到 SQL 2008 DB 的 vb.net 中不起作用
我有一个连接到 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦启动事务,记录就会被锁定,并且在提交或回滚之前无法访问。在 MSDN 上查看这个示例。
此外,
Data.IsolationLevel
适用于连接级别。如果你想进行脏读,你应该使用ReadUncommissed
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 usingReadUncommitted