Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2007, 05:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default 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
Reply With Quote
  #2 (permalink)  
Old February 2nd, 2007, 04:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #3 (permalink)  
Old February 2nd, 2007, 04:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well it's simple in SQL Server 2005, use a try/catch block and the ERROR_MESSAGE() function. In SQL 2000 might read this but it's a lot of work http://www.aspfree.com/c/a/MS-SQL-Se...2000-and-2005/.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #4 (permalink)  
Old February 28th, 2007, 10:43 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can capture a SQL error within a stored procedure or within your client development tool. Am I missing the question?

Reply With Quote
  #5 (permalink)  
Old March 1st, 2007, 08:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #6 (permalink)  
Old March 1st, 2007, 05:04 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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....

Reply With Quote
  #7 (permalink)  
Old March 1st, 2007, 06:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #8 (permalink)  
Old March 1st, 2007, 08:08 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
  #9 (permalink)  
Old March 2nd, 2007, 10:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #10 (permalink)  
Old March 2nd, 2007, 01:50 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to capture java syntax error messages? help.. viber101 Java Databases 2 April 1st, 2009 12:53 AM
SQL Server Reg. SQL Server does not exist error Arsi SQL Server 2000 1 June 11th, 2008 11:20 AM
how to capture 2 SQL queries into 2 datatables hendyhanusin VB.NET 2002/2003 Basics 4 March 26th, 2008 09:31 AM
capture error logs jemacc SQL Server 2000 1 January 10th, 2007 08:17 PM
Error capture from DLL c3r3al_kill3r Classic ASP Components 0 July 1st, 2003 05:55 AM



All times are GMT -4. The time now is 07:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.