February 28, 2012 at 1:42 pm
I have been using the following syntax in prior versions and it worked, however when I try it in 2012 i get an error message....
raiserror 22004 'This is a test'
2012 errors out with
Incorrect syntax near '22004'
any ideas other than fixing all my raiserror commands to the new format. (lots of scripts/stored procedures/triggers)
February 28, 2012 at 2:10 pm
It's a little hard to understand what is wrong since you haven't formatted things well. Do you mean that if you run this:
raiserror 22004 'This is a test'
You get a syntax error? The syntax shows that parens are required. Also, is 22004 in your sysmessages table?
http://msdn.microsoft.com/en-us/library/ms178592%28v=sql.110%29.aspx
February 28, 2012 at 3:05 pm
just an old format i have been using since sql 7/2000
the 22004 was just and arbitrary number that i chose.
if you put the line i supplied into sql 2008 or lower you will get the raiserror message. however, if you try that with sql 2012 you will get a syntax error.
in 2008 no problem works fine, without any error. no need to add an message id to the system it worked.
in 2012 it does not work in the syntax provided. error is syntax error
February 29, 2012 at 3:27 am
I have verified this works in SQL 2008 R2 as well. Seems strange that this was allowed as an option within TSQL. The command clearly states the correct format. As a pointer to a reason why the error occurs is that raiserror is marked with a note that : New applications should use THROW instead in BOL for SQL 2012.
February 29, 2012 at 12:34 pm
well that answered my question. doesnt look like there is setting/configuration change that would make it behave like the older versions. so i will be changing up scripts in the mean time.
March 7, 2012 at 8:01 am
You can use something like this:
RAISERROR('This is a test', 16, 1)
Third parameter is any number you choose, from 0 to 255.
Second parameter:
>=16 then is error.
<=10 and below - informational message.
You also can use placeholder variables to insert values in message text - without concatenation "+". There is also nice option "WITH NOWAIT" (message immediately goes to caller, doesn't wait for batch to finish).
See the doc: http://msdn.microsoft.com/en-us/library/ms178592.aspx
Also, you can check what is your database compatibility level, and set appropriately - could be the solution without code change.
But, if you can, it would be better to change the code to a more current syntax.
May 3, 2012 at 8:07 am
my original post explained it
in mssql 2008 or lower that command worked without having to setup sysmessages for it. in 2012 it no longer works. i originally had written some scripts starting back in mssql 6 prior to mssql 2000 (7). i had been just making minor adjustments through each upgrade. when i moved my scripts to a test mssql 2012 it was full of errors due to my shortened version of the raiseerror command.
it doesn't look like MS is going to add it back in so i have already rewritten my scripts to use the proper format of the raiseerror command along with adding sysmessages.
originally it was just a quick down and dirty method for throwing back and error message that i knew wouldn't be a standard sql error message. so as i wrote a new script for whatever reason i would try to use the same ones as before for the same error message but sometimes i needed to come up with new ones.
well in 2012 they don't work but prior to that they did work.
June 7, 2012 at 8:09 am
roy.tollison (5/3/2012)
my original post explained itin mssql 2008 or lower that command worked without having to setup sysmessages for it. in 2012 it no longer works. i originally had written some scripts starting back in mssql 6 prior to mssql 2000 (7). i had been just making minor adjustments through each upgrade. when i moved my scripts to a test mssql 2012 it was full of errors due to my shortened version of the raiseerror command.
it doesn't look like MS is going to add it back in so i have already rewritten my scripts to use the proper format of the raiseerror command along with adding sysmessages.
originally it was just a quick down and dirty method for throwing back and error message that i knew wouldn't be a standard sql error message. so as i wrote a new script for whatever reason i would try to use the same ones as before for the same error message but sometimes i needed to come up with new ones.
well in 2012 they don't work but prior to that they did work.
Sorry to revive this one but as long as you're rewriting things you might as well use the newer THROW command. From RAISERROR (SQL 2012):
Generates an error message and initiates error processing for the session. RAISERROR can either reference a user-defined message stored in the sys.messages catalog view or build a message dynamically. The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY…CATCH construct.
New applications should use THROW instead.
I am not saying your app is necessarily a "new application" but you already committed to doing "new development". As long as you're making changes why not bring your code to use the most current recommended techniques? Just a thought.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply