I'm calling a SQL Server statement and I know that it might sometimes return
a "violation of unique key constraint" error (SQL Server error 2627). I'd
like to catch this and handle it - something like this:
Try
cmd.ExecuteScal ar()
Catch ex As SqlException
Select Case ex.Number
Case 2627 'Unique constraint violation <-- don't want to
hard code this number
<code to handle violation goes here>
<other cases go here>
End Select
End Try
This is fine, except that I don't want to hard code the value 2627. I
thought there might be some kind of enumeration in ADO.NET that would give
nice names to all these standard errors, but I can't find anything like it.
Is there something I can use, or should I write my own, or just forget about
it and hard-code the error number?
Thanks in advance,
Carl Johansen http://www.carljohansen.co.uk 2 7021
I am not exactly sure if this can be done as it's more or less provider dependent. I can however suggest you to declare constants in a separate class and use them wherever you would want to catch that specific error code, you will have to hard code the error code only once - during it's declaration. But please be aware of the fact that if you declare your constant in an assembly which is different from the assembly that refers to it, you will have to recompile all those assemblies in case you change the value of the constant and yours is not a public assembly, as the actual value of the constant is substituted by the compiler while compiling.
HTH, Metallikanz!
"Carl Johansen" <carl@_NOSPAM_c arljohansen.co. uk> wrote in message news:dd******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com... I'm calling a SQL Server statement and I know that it might sometimes return a "violation of unique key constraint" error (SQL Server error 2627). I'd like to catch this and handle it - something like this: Try cmd.ExecuteScal ar() Catch ex As SqlException Select Case ex.Number Case 2627 'Unique constraint violation <-- don't want to hard code this number <code to handle violation goes here> <other cases go here> End Select End Try This is fine, except that I don't want to hard code the value 2627. I thought there might be some kind of enumeration in ADO.NET that would give nice names to all these standard errors, but I can't find anything like it. Is there something I can use, or should I write my own, or just forget about it and hard-code the error number? Thanks in advance, Carl Johansen http://www.carljohansen.co.uk
I am not exactly sure if this can be done as it's more or less provider dependent. I can however suggest you to declare constants in a separate class and use them wherever you would want to catch that specific error code, you will have to hard code the error code only once - during it's declaration. But please be aware of the fact that if you declare your constant in an assembly which is different from the assembly that refers to it, you will have to recompile all those assemblies in case you change the value of the constant and yours is not a public assembly, as the actual value of the constant is substituted by the compiler while compiling.
HTH, Metallikanz!
"Carl Johansen" <carl@_NOSPAM_c arljohansen.co. uk> wrote in message news:dd******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com... I'm calling a SQL Server statement and I know that it might sometimes return a "violation of unique key constraint" error (SQL Server error 2627). I'd like to catch this and handle it - something like this: Try cmd.ExecuteScal ar() Catch ex As SqlException Select Case ex.Number Case 2627 'Unique constraint violation <-- don't want to hard code this number <code to handle violation goes here> <other cases go here> End Select End Try This is fine, except that I don't want to hard code the value 2627. I thought there might be some kind of enumeration in ADO.NET that would give nice names to all these standard errors, but I can't find anything like it. Is there something I can use, or should I write my own, or just forget about it and hard-code the error number? Thanks in advance, Carl Johansen http://www.carljohansen.co.uk This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Quinet, Joel |
last post by:
Hi all,
I use the Win32 extension (Build 157) module with Python 2.3 to add row in a
sql server 2000 sp3 DB.
My problem is I can not insert data of type money in the DB.
I use the following command to create the parameter :
prm = cmd.CreateParameter('Open', constants.adCurrency,
constants.adParamInput, 8, 12.10)
cmd.Parameters.Append(prm)
|
by: Vince C. |
last post by:
Hi,
I've created a web application with Visual Interdev and I've added Microsoft
XML, version 4 in project's references. A META tag has been successfully added
in global.asa:
<!--METADATA TYPE="TypeLib" NAME="Microsoft XML, v4.0"
UUID="{F5078F18-C551-11D3-89B9-0000F81FE221}" VERSION="4.0"-->
But when I write the following code in an ASP server-side JavaScript:
|
by: Carl Johansen |
last post by:
I'm calling a SQL Server statement and I know that it might sometimes return
a "violation of unique key constraint" error (SQL Server error 2627). I'd
like to catch this and handle it - something like this:
Try
cmd.ExecuteScalar()
Catch ex As SqlException
Select Case ex.Number
Case 2627 'Unique constraint violation <-- don't want to
hard code this number
|
by: Steve Jorgensen |
last post by:
If you've ever employed custom error numbers and messages in you programs,
you've probably ended up with code similar to what I've ended up with in
the past something like...
<code>
public Const xyzcErrNumBase As Long = 500
Public Const xyzcErrNumHeyDontDoThat = xyzcErrNumBase + 1
Public Const xyzcErrTxtHeyDontDoThat = "Hey! Don't do that!"
|
by: Steve Jorgensen |
last post by:
Here is some code to generate code for raising and getting information about
custom errors in an application. Executing the GenerateXyzErrDefs procedure
generates the code.
<tblXyzError>
ErrorCodeOffset (Long Int) ErrorObjBaseName (Text(50))
ErrorDescription (Text(255))
1 DontDoThat
Hey! Don't do that!
| |
by: James Lang |
last post by:
Hi
I am trying to display in an aspx page an image from the employees table in
the sql server 2000 Northhwind database
"Select photo from employees where employeeid = 1"
|
by: Steve |
last post by:
I have a dataset.
I fill it with two recordsets from SQL queries.
Tables are called tblPlanFYSpendingStage, tblSpendingStage.
|
by: Yi Xing |
last post by:
I log into the machine remotely. How do I check the Mac OSX version
number under command line? Thanks.
hiaips rosedb0 at gmail.com
Wed Aug 16 01:23:10 CEST 2006
* Previous message: MySQLdb installation error
* Next message: What would be the best way to run python client in
the background
|
by: Stimp |
last post by:
I've created an aspx page called HistoryManage.aspx.
The page works fine on my local machine but when I load it off the web I
get the following strange error...
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.
|
by: Barry Newberger |
last post by:
I am working on a Outlook COM project. For some reason
win32com.client.constants
quit working between runs of one of my test scripts. It's supposed to
acquire attributes for all constants defined in loaded COM servers
through its __dicts__ attribute,and did for awhile
Now it is throwing an AttributeError:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |