Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27389

Row level locking using OLEDB

$
0
0
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.


Code:

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


Viewing all articles
Browse latest Browse all 27389


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>