Solved

How do you trap the deadlock error code 1205 in VB

Posted on 2006-07-04
5
1,952 Views
Last Modified: 2013-12-25
I am writing an app in VB and using SQL Server 2000 as the DBMS. I want to trap the deadlock error code 1205 in VB. Do I use the normal Err object in VB or the ADODB.Err objects in the connection object to trap it. eg

Option 1

if ABS(Err.Number) =  1205 then
   ...
   ..., etc.

////////////////////////////////////////////////////////////////////////////////
Option 2

Dim Cn as ADODB.Connection
Dim ADOErr As ADODB.Error
   ...
   ...

For Each ADOErr In Cn.Errors
      If Abs(ADOErr.Number) = 1205 Then
         ...
         ..., etc.

I am not in a position to test this before I install the app with the client, so I would appreciate any input from someone who has actually written code to handle this in a real app.

Thank you

0
Comment
Question by:Vincent_Monaghan
5 Comments
 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 200 total points
Comment Utility
Check the "Source" of the err.  If its from MS SQL Server then better trap the error object in ADO
otherwise, use the VB err object.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 200 total points
Comment Utility
The VB6 way, not sure if you are using.NET, and does not take into consideration errors off of connection objects...

on error goto error_handler

'Your code goes here

exit_function:
  on error resume next
  'Destroy any objects here
  exit sub

error_handler:
  Select Case err.Number
     Case 0
         'Not an error, ignor.
     Case 1205
         'You now have the error trapped, handle it here.
     Case Else
         'Handle it gracefully.
   End Select
   resume exit_function

end function

Hope this helps.
-Jim
0
 

Author Comment

by:Vincent_Monaghan
Comment Utility
These are good comments, but on consideration what I need is a slick way of replicating a deadlock situation on my standalone development PC to test that my code will handle a deadlock gracefully.
0
 

Author Comment

by:Vincent_Monaghan
Comment Utility
Thanks
0
 

Expert Comment

by:giyyuni
Comment Utility
Use err.raise to create a deadlock error. But make sure you comment it out in prod.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

5 Experts available now in Live!

Get 1:1 Help Now