Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

T-SQL Error handling

Status
Not open for further replies.

Moptop

Programmer
Joined
Sep 24, 2003
Messages
35
Location
EU
Hi
Is it possible to access the SQL error string.

For instance:
If an INSERT fails due to a FK constraint, I get an error 547 stored in @@error.
I can look up that message using:
select * from master..sysmessages where error = 547
which retrieves:
%ls statement conflicted with %ls %ls constraint '%.*ls'. The conflict occurred in database '%.*ls', table '%.*ls'%ls%.*ls%ls.

What I would like is to get the actual error massage:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'fkSegment_DivisionID'. The conflict occurred in database 'CustomerUK', table 'tblDivision', column 'vchrDivisionID'.
split up by the %ls placeholders.

I know about xp_sscanf but I don't know where to get error message from.

Does anybody have any ideas?

Thanks

Mark
 
sysmessages in Master database has the error messages. Is that what you are looking for?
 
The error message in sysmessages has "%ls statement conflicted with %ls %ls constraint '%.*ls'. The conflict occurred in database '%.*ls', table '%.*ls'%ls%.*ls%ls."

What I need is the output from DBCC OUTPUTBUFFER (spid)

This contains the full error including table names, etc.

i.e. the stuff that goes into the %ls parameters

 
I think I have an answer. I can insert the output of dbcc outputbuffer into a temp table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top