Groups | Blog | Home
all groups > sql server programming > june 2004 >

sql server programming : trapping connection-level errors


toylet
6/10/2004 11:26:27 PM
I have a table with a contraint to avoid duplicated keys.

alter procedure AddKey
@key char(10)
as
declare @errmsg varchar(20)
insert into TheTable values ( @key )
if @@error=0
set @errmsg=""
else
set @errmsg="duplicated key"
select @errmsg as result
return @errmsg

Is it possible to prevent this stored procedure from raising a
connection level error on inserting a duplicated key so that the client
application can retrieve a return code via ODBC and knows that a
duplicated key was inserted.

The client app looks like this:

sqlexec(m.lnHandle, "execute AddKey", "t_view")
? t_view.result


--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.26
Tibor Karaszi
6/11/2004 11:52:11 AM
You cannot currently consume errors in SQL Server. So your option is to ignore the error in the client app.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/


[quoted text, click to view]

AddThis Social Bookmark Button