Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access, pessimestic locking, OLEDB, VB.net

Posted on 2006-10-25
9
Medium Priority
?
909 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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