Advertisement

05.11.2008 at 02:03AM PDT, ID: 23392499
[x]
Attachment Details

how to throw an exception in stored procedures

Asked by mmingfeilam in SQL Server 2005

Tags: microsoft, sql server, 2005

this is a generic stored procedure:

CREATE PROCEDURE [daab_UpdateCustomers]
(
      @CustomerID nchar(5),
      @CompanyName nvarchar(40),
      @ContactName nvarchar(30) = NULL,
      @ContactTitle nvarchar(30) = NULL,
      @Address nvarchar(60) = NULL,
      @City nvarchar(15) = NULL,
      @Region nvarchar(15) = NULL,
      @PostalCode nvarchar(10) = NULL,
      @Country nvarchar(15) = NULL,
      @Phone nvarchar(24) = NULL,
      @Fax nvarchar(24) = NULL
)
AS
BEGIN

      SET NOCOUNT ON
      DECLARE @Err int

      UPDATE [dbo].[Customers]
      SET
            [CustomerID] = @CustomerID,
            [CompanyName] = @CompanyName,
            [ContactName] = @ContactName,
            [ContactTitle] = @ContactTitle,
            [Address] = @Address,
            [City] = @City,
            [Region] = @Region,
            [PostalCode] = @PostalCode,
            [Country] = @Country,
            [Phone] = @Phone,
            [Fax] = @Fax
      WHERE


      SET @Err = @@Error

      RETURN @Err
END
GO

is it possible to raise an error/throw an exception that the c# application calling the stored procedure can catch?  thanks.
Start Free Trial
[+][-]05.11.2008 at 02:22AM PDT, ID: 21541930

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.13.2008 at 09:16AM PDT, ID: 21556549

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.21.2008 at 08:17AM PDT, ID: 21615937

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: microsoft, sql server, 2005
Sign Up Now!
Solution Provided By: bryhhh
Participating Experts: 3
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628