|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
January 12th, 2007, 05:43 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Capture Sql server Error
Hi,
Has anyone tried to capture the error that SQL server throws when an sql statement results error. I know DBCC OUTPUTBUFFER holds the error in hexadecimals. But I wanted to know if anyone ever succeeded on interpretting the outputbuffer and capture the exact error that sql server returns.
Eg:
Code:
create table tbltest ( col1 int )
go
Insert tbltest values ('1abc')
The above insert statement results int he following error.
Code:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '1abc' to a column of data type int.
Here... I wish to capture
Syntax error converting the varchar value '1abc' to a column of data type int. This is what being returned by DBCC OUTPUTBUFFER as hexadecimal values.
Hope that explains.
Cheers.
_________________________
- Vijay G
Strive for Perfection
__________________
- Vijay G
|
February 2nd, 2007, 04:41 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
65 Views on this topic, but no replies?
Seems no one came across such a requirement yet. Any luck BTW? Let me know.
Cheers.
_________________________
- Vijay G
Strive for Perfection
|
February 28th, 2007, 10:43 PM
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can capture a SQL error within a stored procedure or within your client development tool. Am I missing the question?
|
March 1st, 2007, 08:00 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Yes rob, error handling using @@ERROR is the standard method followed in stored procedure. Client development tool is completely ruled out in this case. As my intention is to capture it from the sql server, say with a stored procedure, and get the exact error that the sql server throws in usch cases. @@ERROR results in INT value which can be used to decide if it is success or failure. I wanted to go a level above and capture the error that sql server returns from the sysmessages table using xp_printf and stuff with the % and *ls etc... replaced as shown below
Code:
Incorrect syntax near '%.*ls'.
Hope that explains.
Yes Joe, It is tough in sql server 2000, the sad thing is I wanted to accomplish this in 2000, not in 2005.
Thanks for your replies.
Cheers
_________________________
- Vijay G
Strive for Perfection
|
March 1st, 2007, 05:04 PM
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am mostly understanding you. Are you saying with @@error you ARE getting the int value of the error but want to know what the verbal description of that error is? If possible please describes the steps your doing up to where your not getting the results you want. Also explain what you are getting....
|
March 1st, 2007, 06:39 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
As I mentioned in my post at the beginning, DBCC OUTPUTBUFFER results the error description, but in hexadecimals. I am looking for a way to parse and capture from it. It is kind of tough.
All I wanted to know is, is there a way in doing this in sql server 2000? I even found the sample shown in Joe's reply not helping.
Cheers
_________________________
- Vijay G
Strive for Perfection
|
March 1st, 2007, 08:08 PM
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So you want to capture this??? and have the SQL server return this in a result set?:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '1abc' to a column of data type int.
|
March 2nd, 2007, 10:59 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Yes exactly... atleast the second line...
Syntax error converting the varchar value '1abc' to a column of data type int.
_________________________
- Vijay G
Strive for Perfection
|
March 2nd, 2007, 01:50 PM
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok I think I understand you but I am still not sure. You can capture the description of the error and put that in a result set and return it to the calling application in a stored procedure or have the stored proc print the error message to capture that clients side. I have seen some sites that insert the error information into an error table. Is that what your trying to do?
|
|
|