all groups > sql server programming > july 2004 >
You're in the

sql server programming

group:

SQL Error Messages


SQL Error Messages Jay
7/8/2004 11:00:02 PM
sql server programming:
I have a stored procedure where I try to insert into a table. Some =
times the insert will fail because of a primary key constraint. I want =
to ignore that message. I want my VB.NET program to not even be aware =
of the error. Even though I handle the error in the SP using @@error I =
cannot stop SQL Server from notifying my program that an error occured. =
Is there anyway to turn off error notification for this few lines of =
code?

Thanks

RE: SQL Error Messages Beeeeeeeeeeeeves
7/9/2004 1:30:01 AM
If you want to isolate this from your VB.NET program you could either do one of two things, get it to handle the exception that would be thrown and then ignore it, or create a stored procedure that only inserts if the record doesn't already exist in the PK constraint. The latter is preferable performance-wise as you don't have the overhead of an exception, but it largely depends on your preferences what you do





[quoted text, click to view]
Re: SQL Error Messages Aaron [SQL Server MVP]
7/9/2004 9:16:55 AM
You can avoid the data in all layers by ensuring the data doesn't exist in
the first place.

IF NOT EXISTS (SELECT 1 FROM table WHERE (clause that violates primary key
given input data))
INSERT table ...

--
http://www.aspfaq.com/
(Reverse address to reply.)




[quoted text, click to view]
I have a stored procedure where I try to insert into a table. Some times
the insert will fail because of a primary key constraint. I want to ignore
that message. I want my VB.NET program to not even be aware of the error.
Even though I handle the error in the SP using @@error I cannot stop SQL
Server from notifying my program that an error occured. Is there anyway to
turn off error notification for this few lines of code?

Thanks

Jay

Re: SQL Error Messages Greg Linwood
7/9/2004 2:43:58 PM
Hi Jay

Unfortunately, there isn't any way to do that using the technology as =
is. Sorry for the bad news!

Generally speaking, this is something you have to take into =
consideration when designing your application. As a result of this =
limitation, it's common to implment complex error handling logic in =
application data tier layer.

Regards,
Greg Linwood
SQL Server MVP

[quoted text, click to view]
I have a stored procedure where I try to insert into a table. Some =
times the insert will fail because of a primary key constraint. I want =
to ignore that message. I want my VB.NET program to not even be aware =
of the error. Even though I handle the error in the SP using @@error I =
cannot stop SQL Server from notifying my program that an error occured. =
Is there anyway to turn off error notification for this few lines of =
code?

Thanks

Re: SQL Error Messages Jay
7/12/2004 4:08:30 AM
Thanks. You made me think about my situation a little more clear. =
Rather than trying the insert and then detecting the error I just use a =
select to determine if an ID exists in the DB -- much be
[quoted text, click to view]
Hi Jay

Unfortunately, there isn't any way to do that using the technology as =
is. Sorry for the bad news!

Generally speaking, this is something you have to take into =
consideration when designing your application. As a result of this =
limitation, it's common to implment complex error handling logic in =
application data tier layer.

Regards,
Greg Linwood
SQL Server MVP

[quoted text, click to view]
I have a stored procedure where I try to insert into a table. Some =
times the insert will fail because of a primary key constraint. I want =
to ignore that message. I want my VB.NET program to not even be aware =
of the error. Even though I handle the error in the SP using @@error I =
cannot stop SQL Server from notifying my program that an error occured. =
Is there anyway to turn off error notification for this few lines of =
code?

Thanks

AddThis Social Bookmark Button