473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ERROR_STATE() Always = 0?

Below is the contents of a SPROC I have. I want to return the error
info in the catch block for it so I call RaiseError. But the
ERROR_STATE() always comes up as 0 which is ilegal since it must be
between 1-127 I guess. So I wrote a stupid if block to set it to 1 to
stop that error.

But I'd really rather not do this. Can anyone tell what's wrong? Why am
I not getting a correct return from ERROR_STATE()?

Thanx much:

BEGIN TRY
BEGIN TRANSACTION
DELETE FROM WebUser2Role WHERE WebUserID = @WebUserID

INSERT INTO WebUser2Role
SELECT value, @WebUserID FROM fIntList2Table(@RoleIDList)
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000)
DECLARE @ErrorSeverity INT
DECLARE @ErrorState INT

SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();

IF @ErrorState = 0
BEGIN
SET @ErrorState = 1
END

IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION
END

RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState )

END CATCH

IF @@TRANCOUNT > 0
BEGIN
COMMIT TRANSACTION
END

Mar 31 '06 #1
2 4787
The only thing I can think of which may help is that
Errors with a severity of 10 or lower are considered warnings or
informational messages, and are not handled by TRY.CATCH blocks.
therefore maybe it's not recognised as an error ?
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
<wa********@yahoo.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Below is the contents of a SPROC I have. I want to return the error
info in the catch block for it so I call RaiseError. But the
ERROR_STATE() always comes up as 0 which is ilegal since it must be
between 1-127 I guess. So I wrote a stupid if block to set it to 1 to
stop that error.

But I'd really rather not do this. Can anyone tell what's wrong? Why am
I not getting a correct return from ERROR_STATE()?

Thanx much:

BEGIN TRY
BEGIN TRANSACTION
DELETE FROM WebUser2Role WHERE WebUserID = @WebUserID

INSERT INTO WebUser2Role
SELECT value, @WebUserID FROM fIntList2Table(@RoleIDList)
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000)
DECLARE @ErrorSeverity INT
DECLARE @ErrorState INT

SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();

IF @ErrorState = 0
BEGIN
SET @ErrorState = 1
END

IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION
END

RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState )

END CATCH

IF @@TRANCOUNT > 0
BEGIN
COMMIT TRANSACTION
END

Mar 31 '06 #2
No it deffinately is going into the catch block.

But ERROR_STATE() in the catch block returns 0. This poses a problem
when I call RaiseError because 0 is not a valid state.

Mar 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Randell D. | last post by:
Folks, I test if my PHP should process form data by checking if $_POST is an array - However I always find its condition proves true - Why or alternatvily, what other method can one use to check...
2
by: db2group88 | last post by:
i would like to know when i create a table with identity column, should i used generated by default or generated as always. since when i create this table, i might copy some data from another table...
3
by: cody | last post by:
why foreach does always have to declare a new variable? I have to write foreach (int n in array){} but Iam not allowed to write: int n=0; foreach (n in array){}
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
6
by: Tim::.. | last post by:
Can someone tell me why the value of my Boolean is always false! Even after I have declared that my variable iNews should equal TRUE it seems to remain false... Can some please explain why... ...
8
by: Peter | last post by:
Hi, there I have created an stored procedure using the DDL below for my MS Access Database and no error occurs. Also it can create an stored procedure if I changed the parameter from "" to...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
0
by: peter.bittner | last post by:
I have developed a Windows application in Visual Studio .NET 2003 and created a Setup project for it. In the File System Editor I have added a shortcut to the User's Desktop folder to point to the...
30
by: Brian | last post by:
I am using Borland C++ Builder 5 for my application. When I build my application, it states that I have several if-statements that will always be false. The statements appear correct, so could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.