Solved

Access, pessimestic locking, OLEDB, VB.net

Posted on 2006-10-25
9
730 Views
Last Modified: 2008-02-01
How do you do pessimestic locking using OLEDB objects to access a Jet database (Access 2002). I must be dense, cant find documentation on it.
0
Comment
Question by:MikeBroderick
  • 5
  • 3
9 Comments
 
LVL 15

Expert Comment

by:MNelson831
ID: 17806486
Thats because you're spelling "pessimistic" incorrectly.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17806585
ok, assuming u are using ADO here
u have defined your ado connection object already


'adoConnection is your ADODB.Connection object
'adoRecSet is your ADODB.Recordset object

    adoRecSet.ActiveConnection = adoConnection
    adoRecSet.CursorType = adOpenKeyset
    adoRecSet.LockType = adLockPessimistic            
    adoRecSet.CursorLocation = adUseClient
   
    adoRecSet.Open "SELECT * FROM Num"

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17806592
urm, bugger, u said vb.net right?
i gues u need ado.net ?
does my code give u a headstart?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17806622
probably not eh

does this help any
http://builder.com.com/5100-6388-1049842.html
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:MikeBroderick
ID: 17806946
I'm not sure if it is OLEDB or ADO. Here are my declarations:

    Dim jCon1 As New OleDbConnection
    Dim jSelCmd1 As New OleDbCommand
    Dim jAdpt1 As New OleDbDataAdapter
    Dim jParm1 As OleDbParameter
    Dim jTx1 As OleDbTransaction
    Dim jRdrCmd1 As New OleDbCommand
    Dim jDataRdr As OleDbDataReader
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17807123
ADO.Net by the looks of things and probably using OLEDB also,

ADO.Net uses the optimistic architecture. Apparently Pessimistic locking aint useful for multiuser environment (so ive read somewhere) as it locks the row when u retrieve the record for editing

I found an example here that may help
http://www.microsoft.com/mspress/books/sampchap/5354i.asp



You talked about optimistic concurrency only. How do I handle pessimistic concurrency in ADO.NET?

A

With pessimistic concurrency, you lock the row before you start making your changes. Because the contents of the DataSet are disconnected from the database, there is no simple way to lock the data in the database before you modify a row in a DataSet. However, you can achieve similar functionality using transactions.

Let's say you want to lock data in your database before the user modifies data on the screen to ensure that the user's changes will succeed. You could open a transaction and lock those rows in the database so that other users cannot modify those rows by issuing the following query within the transaction:


SELECT * FROM [Order Details] HOLDLOCK WHERE OrderID =  10503

NOTE
--------------------------------------------------------------------------------

This query was written specifically for SQL Server 2000. Not all databases support this query syntax. If you're working with another database, see your database's documentation for information on how to lock data in a query.
This approach has some major drawbacks. What if your user forgets to click the Submit Changes button in your application and strolls off to the kitchen to grab a donut and some caffeine? Those rows in the database are locked. The more data you lock and the longer you maintain those locks, the less scalable your application becomes.




I dont expect that example sql to work, I posted for info only

Can u have a look at the properties of OleDBConnection, is there a locktype property anywhere?
0
 

Author Comment

by:MikeBroderick
ID: 17810972
Regarding the SQL statement

SELECT * FROM [Order Details] HOLDLOCK WHERE OrderID =  10503

Do you need a cursor and a FETCH statement? I tried the holdlock option with a transaction and it didnt work. I noticed the cursor/fetch in the SQL manual.

I'm aware of the drawbacks with pess locking. This routine is a tight one. It reads, increments, and updates all in one procedure.
0
 

Author Comment

by:MikeBroderick
ID: 17811099
I tried HOLDLOCK's cousin XLOCK and it did what I wanted. Thanks for pointing me in the right direction.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17811251
Cool stuff, excellent

Best of luck then with the rest of your project especially the use of pessimistic locking
Funny how that is okay with VB/ADO/Access but not in favour with .Net
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Alter an update query which rounds 7 33
Dropdown Not In List - not working correctly 11 38
Web based Access Database and licencing 5 30
access pop-up form 3 19
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now