Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
matt_calhoon
Posting Yak Master
235 Posts |
Posted - 2002-02-15 : 04:02:04
|
| Hi there,a question with regards to a transaction. If a syntax error is returned is there any way to trap this and display the error? I have a table (tblCategories) which has an int field and a varchar field. I am forcing a syntax error by inserting the incorrect datatype into the tblCategories. I want to log the error in the stored proc "p_INSERT_ERRORLOG".Take the following sql statement:BEGIN TRAN INSERT_DATASET IDENTITY_INSERT tblCategories ONgo DECLARE @MSG varchar(500) Insert into tblCategories (CATID, TITLE) VALUES ('asdf','2') return IF @@ERROR <> 0 BEGIN ROLLBACK TRANSACTION INSERT_DATA exec p_INSERT_ERRORLOG 'FAILED' END ELSE BEGIN COMMIT TRAN INSERT_DATA exec p_INSERT_ERRORLOG 'SUCCESS' ENDBut all I get is the syntax error returned:Server: Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'asdf' to a column of data type int.Any ideas on this?thanks - matt |
|
|
matt_calhoon
Posting Yak Master
235 Posts |
Posted - 2002-02-15 : 04:11:41
|
| - i better add that this script is called from within a DTS 'execute SQL task' and not from a stored proc...just in case it mattered. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-02-15 : 14:48:06
|
| In DTS, you can create ON FAILURE and ON SUCCESS flow controls. This may be your best alternative.------------------------GENERAL-ly speaking... |
 |
|
|
matt_calhoon
Posting Yak Master
235 Posts |
Posted - 2002-02-15 : 18:43:33
|
| this script is actually contained in a task which was followed by a success flow control - I am double checking the integrity of the data. |
 |
|
|
|
|
|