Solved

Access, pessimestic locking, OLEDB, VB.net

Posted on 2006-10-25
9
829 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Expert Comment

by:rockiroads
ID: 17806622
probably not eh

does this help any
http://builder.com.com/5100-6388-1049842.html
0
 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

690 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