|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Error MessageHi,
Is there any way to get the error message within a stored procedure. I have to store the SQL Server error message in a table. TIA Thanks P In SQL Server 2005, you can use a TRY CATCH block similar to languages like
C# etc and use ERROR_MESSAGE() function for getting the error text. In SQL Server 2000, you will have to use RAISEERROR. Show quote "Prasad" wrote: > Hi, > Is there any way to get the error message within a stored procedure. I > have to store the SQL Server error message in a table. > > > TIA > Thanks > P > > > Thnx Karthik
But I want something that is common to both SQL Server versions (2000 and 2005) And AFIK the RAISEERROR generates a user defined message, I wanted the error message that SQL Server generates. Thanks P Show quote "Karthik" <Kart***@discussions.microsoft.com> wrote in message news:872116FB-5C9D-47BA-B322-0303A0BACEAF@microsoft.com... > In SQL Server 2005, you can use a TRY CATCH block similar to languages > like > C# etc and use ERROR_MESSAGE() function for getting the error text. > > In SQL Server 2000, you will have to use RAISEERROR. > > "Prasad" wrote: > >> Hi, >> Is there any way to get the error message within a stored procedure. >> I >> have to store the SQL Server error message in a table. >> >> >> TIA >> Thanks >> P >> >> >> You can't get to the error message at the TSQL level in 2000 or earlier. Only @@ERROR, which is the
error number. -- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ "Prasad" <ekke_nik***@yahoo.co.uk> wrote in message news:%23Zs4uZk0GHA.4796@TK2MSFTNGP03.phx.gbl... > Thnx Karthik > But I want something that is common to both SQL Server versions (2000 and 2005) > And AFIK the RAISEERROR generates a user defined message, I wanted the error message that SQL > Server generates. > > Thanks > P > > "Karthik" <Kart***@discussions.microsoft.com> wrote in message > news:872116FB-5C9D-47BA-B322-0303A0BACEAF@microsoft.com... >> In SQL Server 2005, you can use a TRY CATCH block similar to languages like >> C# etc and use ERROR_MESSAGE() function for getting the error text. >> >> In SQL Server 2000, you will have to use RAISEERROR. >> >> "Prasad" wrote: >> >>> Hi, >>> Is there any way to get the error message within a stored procedure. I >>> have to store the SQL Server error message in a table. >>> >>> >>> TIA >>> Thanks >>> P >>> >>> >>> > > Prasad (ekke_nik***@yahoo.co.uk) writes:
> But I want something that is common to both SQL Server versions (2000 There isn't any. The best you can do on SQL 2000 is to use @@error to > and 2005) retrieve the message text from sysmessages. But then you will only get placeholders for parameterised strings. If you need to save the full error message on SQL 2000, you can only do this from the client. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Other interesting topics
|
|||||||||||||||||||||||