Solved

Access, pessimestic locking, OLEDB, VB.net

Posted on 2006-10-25
9
692 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

707 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

13 Experts available now in Live!

Get 1:1 Help Now