Solved

How do you trap the deadlock error code 1205 in VB

Posted on 2006-07-04
5
2,021 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
[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 Comments
 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 200 total points
ID: 17039975
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
ID: 17144054
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
ID: 17144794
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
ID: 17279964
Thanks
0
 

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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