Record Locking in MS SQL Server 2000 using VB app.

I converted the access database into ms sql server and I am using VB 6.0 app for front end interface. The problem is that I lost the record locking feature. The vb app does not recognize if the record is locked or not. I need to know the best way to have record locking for concurrent processes. Is there any stored procedure available that I can directly call or some other better way? Please let me know. Thanks!
Here is the code I am using for checking if the record is lock or not:

'Test method to determine whether a record is locked or not before editing it
Public Function IsItLocked(rstAny As ADODB.Recordset) As Boolean
    On Error GoTo IsItLocked_Error
    IsItLocked = False
   
    rstAny.Fields(0).Value = rstAny.Fields(0).Value
    Exit Function
   
IsItLocked_Error:
   
    If Err.Number = -2147467259 Then
        IsItLocked = True
        Exit Function
    Else
        MsgBox "Error #" & Err.Number & vbCrLf & Err.Description, vbCritical, "Unknown Error Found!"
    End If
End Function

Public Sub LockRecord(rstAny As ADODB.Recordset)
    ADODBConn.BeginTrans
    gblnInTrans = True
    rstAny.Fields(0).Value = rstAny.Fields(0).Value 'record should lock occur here
   
End Sub
US-ITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leclairmCommented:
What lock type is your recordset using??
0
US-ITAuthor Commented:
It is  'adLockPessimistic' and the cursor type is 'adOpenKeyset'.

thanks!
0
leclairmCommented:
I don't have books online on the computer I'm at now, but I know there is a locking hints section that explains how to lock records directly in your query.

Here's a head start:
http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

US-ITAuthor Commented:
It's a great site, but I need a quicker solution. Do you have a working code in VB to invoke a lock and check if it is locked?
0
leclairmCommented:
You can use the UPDLOCK locking with your select which will ensure nothing changes during your transaction.  I would try using begin trans / commit trans with a boolean variable that is set to true during your transaction that has a lock on the row/table and it's set to false after the commit trans.

I've never done this before though, so I'm not sure of any other methods of doing this.

More info...

http://www.informit.com/articles/article.asp?p=27020&rl=1
0
US-ITAuthor Commented:
How would I determine whether the record is locked or not?
0
leclairmCommented:
You would have to pass the lock mode in your select statement, so I would imagine your lockrecord function should work.  Not so sure about the IsItLocked function though.

Sorry I couldn't be much more help...
0
US-ITAuthor Commented:
I tried and it did not work. thanks anyway. Is anyone else can be able to help in this problem?
0
g_johnsonCommented:
I don't think you can read if a SQL table has a lock applied.  If your application owns the database and/or table, you can set up another table to keep track of your locks so that your program doesn't attempt to do something you don't want it to do.  E.g., if user "A" is updating Table "T", don't let user "B" update table "T"

Does that help?
0
US-ITAuthor Commented:
Well, I am able read a record while another client is updating it. I applied this trick before, but did not find it efficient.  This adds more complexity and problems. I want to keep it simple. Any other suggestions?
0
US-ITAuthor Commented:
Also, I am able to update it while someone else is editing it.
0
Anthony PerkinsCommented:
If you are going to resort to editing in a recordset instead of using INSERT/UPDATE/DELETE statements than you are going to have to add a flag in the record to indicate whether the rows is being edited or not.  You will also have to allow for the user that "went to lunch" and left the row "locked"
0
US-ITAuthor Commented:
well, how would the client knows if the record is locked. Is there any stored procedure that can provide this information?
0
Anthony PerkinsCommented:
The simple answer is you do not.  You can only assume that if the row is "locked" for more than x number of minutes than it is time to "unlock" it.  This can be done manually or a job that runs every x minutes to clear all old locks.

I am afraid to say, that is the best you can do with recordset editing.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony PerkinsCommented:
I believe I answered the question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.