473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

error handling with SQL Server

Hi all -

I have a web application and I want to be able to do some basic error
handling. For example, here is one error I would like to catch and
display in a useful way for the user:

-----------------
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]UPDATE statement
conflicted with COLUMN FOREIGN KEY constraint
'FK_tbl_DemographicInfo_tbl_LookupCurrentLiving'. The conflict occurred
in database 'asian_task_force', table 'tbl_LookupCurrentLiving', column
'Code'.

/ASAPOnline/demoProcess.asp, line 271
-----------------

The error is straightforward to you and me. People reading this
newsgroup know why this error would occur and what it means. What is
not straightforward is how I can get the relevant info I need from the
error and return it to the user.

BTW, the line referenced, line 271, is a call to a stored procedure:
cmd.Execute
[cmd is set up as: set cmd = Server.CreateObject("ADODB.Command")]

An end user is not going to know what this error means. What I would
really like to be able to do is to determine that it's a foreign key
contrainst error and tell the user which field/table is causing the
error. If I can't get the actual table/field easily, I would like to at
least be able to determine that it's a foreign key constraint and
provide some text to the that explains what the heck that means in
plain english.

My problem is that I don't even know where to do this. I tried doing
this in the ASP code, and I was able to get this much:

---------------
Description: [Microsoft][ODBC SQL Server Driver][SQL Server]UPDATE
statement conflicted with COLUMN FOREIGN KEY constraint
'FK_tbl_DemographicInfo_tbl_LookupCurrentLiving'. The conflict occurred
in database 'asian_task_force', table 'tbl_LookupCurrentLiving', column
'Code'.
HelpContext: 0
helpfile:
number: -2147217900
Source: Microsoft OLE DB Provider for ODBC Drivers
---------------

which is from the Err object that ASP returns. Still though, the fact
that it's a foreign key constraint error and the tables that are
involved are burried in the Err.Description text.

So would I be able to break this info out in my stored proc? I know
the message for the error is in the sysmessages table, in this case:

----------
%ls statement conflicted with %ls %ls constraint '%.*ls'. The conflict
occurred in database '%.*ls', table '%.*ls'%ls%.*ls%ls.
----------

Is there any way I can get access to these "%ls" variables and then do
something with them? If so, where would I do this, in the stored proc,
in the ASP code, or elsewhere? Or is this an issue in the nebulous
region (read: the region I know very little about) of ODBC/OLE or ADO?
Help!

thanks in advance,
jon
jlarosa at alumni dot brown dot edu

Jul 22 '05 #1
1 2912
Jon,

To get a clear understanding about Error Handling in stored Procs, see

http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html

--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Jon LaRosa" <jl*****@alumni.brown.edu> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi all -

I have a web application and I want to be able to do some basic error
handling. For example, here is one error I would like to catch and
display in a useful way for the user:

-----------------
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]UPDATE statement
conflicted with COLUMN FOREIGN KEY constraint
'FK_tbl_DemographicInfo_tbl_LookupCurrentLiving'. The conflict occurred
in database 'asian_task_force', table 'tbl_LookupCurrentLiving', column
'Code'.

/ASAPOnline/demoProcess.asp, line 271
-----------------

The error is straightforward to you and me. People reading this
newsgroup know why this error would occur and what it means. What is
not straightforward is how I can get the relevant info I need from the
error and return it to the user.

BTW, the line referenced, line 271, is a call to a stored procedure:
cmd.Execute
[cmd is set up as: set cmd = Server.CreateObject("ADODB.Command")]

An end user is not going to know what this error means. What I would
really like to be able to do is to determine that it's a foreign key
contrainst error and tell the user which field/table is causing the
error. If I can't get the actual table/field easily, I would like to at
least be able to determine that it's a foreign key constraint and
provide some text to the that explains what the heck that means in
plain english.

My problem is that I don't even know where to do this. I tried doing
this in the ASP code, and I was able to get this much:

---------------
Description: [Microsoft][ODBC SQL Server Driver][SQL Server]UPDATE
statement conflicted with COLUMN FOREIGN KEY constraint
'FK_tbl_DemographicInfo_tbl_LookupCurrentLiving'. The conflict occurred
in database 'asian_task_force', table 'tbl_LookupCurrentLiving', column
'Code'.
HelpContext: 0
helpfile:
number: -2147217900
Source: Microsoft OLE DB Provider for ODBC Drivers
---------------

which is from the Err object that ASP returns. Still though, the fact
that it's a foreign key constraint error and the tables that are
involved are burried in the Err.Description text.

So would I be able to break this info out in my stored proc? I know
the message for the error is in the sysmessages table, in this case:

----------
%ls statement conflicted with %ls %ls constraint '%.*ls'. The conflict
occurred in database '%.*ls', table '%.*ls'%ls%.*ls%ls.
----------

Is there any way I can get access to these "%ls" variables and then do
something with them? If so, where would I do this, in the stored proc,
in the ASP code, or elsewhere? Or is this an issue in the nebulous
region (read: the region I know very little about) of ODBC/OLE or ADO?
Help!

thanks in advance,
jon
jlarosa at alumni dot brown dot edu

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
0
by: Erland Sommarskog | last post by:
I've added two more articles to my web site. Both are about error handling in SQL Server. I also cover ADO to some extent. The articles are "Error Handling in SQL Server - a Background",...
1
by: Bill S. | last post by:
Hi, I a stored procedure that inserts a record into a table as below. The insert works OK, but if the insert violates a unique indewx constraint on one of the columns, the proc terminates...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
1
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
1
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement...
4
by: Eugene Anthony | last post by:
One problem with the code bellow is after this code conn.qDupUser p1,rs I added: set rs = nothing to test the error handling capability.
9
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.