使用OLEDB进行行级锁定 [英] Row level locking using OLEDB
本文介绍了使用OLEDB进行行级锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码是更新MS-ACCESS数据库中一行的值。
如果我使用相同的代码(sqldb)来更新sql表,请在''.commit'上保留断点'然后没有其他连接(用户)可以读取或更新同一行(a = 1),但可以更新同一个表的其他行
但是对于ms-access ,保持''。'''的断点,整个表被锁定以进行更新(错误:无法更新;当前已锁定)!?
是有没有办法用oledb锁定单行?
谢谢你。
Below code is to update a value of one row in MS-ACCESS db.
If i use the same code(sqldb) to update sql table , keeping break point on ''.commit'' then no other connection(user) can read or update the same row (a = 1), but can update other rows of same table
But for ms-access, keeping break point on ''.commit'', the entire table is locked for update(err:"could not update; currently locked") !?
Is there a way to lock single row using "oledb" ?
thank u.
Dim sConn As OleDbConnection
sConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Pc99\d\db\Accounts.mdb;")
Dim sTransaction As OleDbTransaction
Dim OleCmd As OleDbCommand
Try
sConn.Open()
OleCmd = New OleDbCommand("update tableA set b = b + 1 where a = 1", sConn)
sTransaction = sConn.BeginTransaction()
OleCmd.Transaction = sTransaction
call OleCmd.ExecuteNonQuery()
sTransaction.Commit() 'commit transation
Catch ex As Exception
sTransaction.Rollback() 'rollback transaction
End Try
推荐答案
不! MS Access不是一个多用户数据库,它在文档中就是这么说的,因此它具有PAGE锁定功能。这是正确的,它抓住了桌子末端的一大块记录并锁定了地段,因为只有1个用户,所以它不会给老鼠。
这个问题太老了,它可能早于CP上的一些开发人员,使用它或移动到适当的数据库(SQL Server)。
NO! MS Access is not a multi user database, it says so right there in the documentation, therefore it has PAGE locking. Thats right it grabs a whole chunk of records at the end of the table and lock the lot because there should only be 1 user so it does not give a rats.
This problem is so old it probably predates some of the developers here on CP, live with it or move on the a proper database (SQL Server).
这篇关于使用OLEDB进行行级锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文