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
Solved

Access, pessimestic locking, OLEDB, VB.net

Posted on 2006-10-25
9
770 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 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