Suppressing SQLExceptions...

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi, we're using STored Procedures with MS-SQL and VS.net.
When the SP code attempts to insert a record and there is
a primary key violation, the check for for @@error inside
the SP would catch it. In our case, this is a business
issue, the SP would subsequently do some other processing
and finally do a custom RAISERROR or even nothing.

Unfortunately, the attempted INSERT statement does cause a
ms-sql error which leads to a SQLException on the client
side, which the client code has to deal with even though
the SP either does a custom RAISERROR later or completes
fine.

Is there a way to suppress the SQLException for the INSERT
error (either on the client or ms-sql side).
Unfortunately, the SQLException is generated while the
rest of the SP is still processing and the client code
gets confused. Any bit of sample code specific to this
issue would be very much appreciated.
 
The primary key violation exception has a unique error number.
You then ignore that exception type and proceed.
 
The best bet is to create a data layer that "suppresses" the error and have
the client talk to it. You can have the client contact a web service (or
remoting, ie web service by another name that is not attached to HTTP). You
cannot suppress the exception, only trap it and choose to ignore it. If the
client talks to SQL Server, it has to be client side.

From SQL, you can alter your sproc to not throw an error. If the sproc is
used by other apps that need the error, you can wrap it in another sproc,
for this application, and have that sproc return something other than an
error.

Without knowing the architecture of your app, I am flying blind.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top