I have a stored procedure where I do an INSERT and then a RAISERROR("MyException", 5, 5) in this case the insert fails.
The problem is that the result to my .NET application is
MyException: Cannot insert the value NULL...
So it returns 2 exceptions in one.
My .NET code have always just matched the entire string against "MyException" but that do not work anymore.
Is this standard? And if so, how could this have been working before? Is there any settings for this?
edit :
Im using .NET table adapter to work with the SQL database.
Version
Product : Microsoft SQL Server Enterprice(64-bit) Version : 11.0.2100.60 Cluster : False HADR : False
Microsoft Framework .NET 4.6.2
Stored Procedure
ALTER Procedure [dbo].[up_kod_text_save]
-- Add the parameters for the stored procedure here
@entity_id int,
@text varchar(300),
@kod_key int,
@kod_id int,
@korttext varchar(10),
@inaktiv bit,
@primar_extern_kod varchar(300),
@sparad_av varchar(128),
@kod_typ_id int,
@kod varchar(20),
@original_rowver rowversion,
@associerat_varde decimal(18,5),
@beskrivning varchar(2000),
@viktigt_varde bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @resultat table(kod_id int, uppdat_tidpunkt datetime, rowver binary(8) );
Insert into @resultat
exec up_kod_save @kod_id,@text,@korttext,@inaktiv,@primar_extern_kod,@sparad_av,@kod_typ_id,@kod,@original_rowver, @associerat_varde, @beskrivning,@viktigt_varde
declare @uppdat_tidpunkt datetime
declare @rowver rowversion
declare @tablename varchar(30)
declare @idname varchar(30)
SET @rowver = (SELECT rowver FROM @resultat)
SET @kod_id = (SELECT kod_id from @resultat)
------------------------------------------------------------------------------------
set @uppdat_tidpunkt = getdate()
IF(@kod_key = 2)
BEGIN
ELSE IF(@kod_key = 11)
BEGIN
IF EXISTS ( SELECT akut_checklista_id FROM akut_checklista WHERE akut_checklista_id = @entity_id )
BEGIN
UPDATE akut_checklista
SET [text] = @text,
[kod_id] = @kod_id
WHERE akut_checklista_id = @entity_id
END
ELSE
BEGIN
-- Skapa master-rad
INSERT INTO [akut_checklista] ([text], [kod_id])
VALUES (@text, @kod_id);
set @entity_id = SCOPE_IDENTITY()
END
END
ELSE
BEGIN
RAISERROR ('MyApp_EXCEPTION_UPPDATERAD_AV_ANNAN',16,1)
RETURN
END
SELECT @entity_id as entity_id, @rowver as rowver, @kod_id as kod_id, @uppdat_tidpunkt as uppdat_tidpunkt
The up_kod_save is only updating\inserting without any transaction. It might however fail if rowversion is wrong.
RAISERRORto throw an exception. TryRAISERROR('MyException',16,5). Note the single quotes allow you to run withQUOTED_IDENTIFIER ON, a best practice.