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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-07-08 : 08:51:23
|
| Andrea Moro writes "I need to trap error of sql script without that sql server hang up.This is my test case. A table with a unique constraint. I insert a record via stored procedure and all it's ok. I try to insert the same record, and obiously sql let back violation constraint error.Well, probelm is that sql stop execution of stored procedure giving me back error. I want instead to put a sort of "exception" (oracle) or "on error resume next" (vb) or it's ok just a "on error goto to" so i can trap for myself error.In this way, via vb or asp stored procedure continue to be executed, and when error occur i fill the error output parameter with 0 or with 1 plus my own error message.I tryed to use als sp_executesql. In this way into the sql query analizer error is trapped, but stored continue to be executed until the end. Every error, i check if @@error is <> 0 and when istart the rollback operation.Problem continue to persist under vb, that don't complete the connection.execute operation and in working enviroment mean hang up of vb application, because i cannot trap in the right way the sql server error.How can i solve this problem?Bye Andrea MORO" |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-07-08 : 09:35:56
|
| T-SQL doesn't provide this type of error try-catch type thing...Use a where not exists clause in your insert statement. Or write an instead of trigger for the table.<O> |
 |
|
|
MakeYourDaddyProud
184 Posts |
Posted - 2002-07-08 : 10:22:10
|
| Take a look at RAISERROR statements in T-SQL to help set up your Errors collection in ADO and inspect the values. Not sure if a RETURN out of sp clears it. Search MSDN for more info.You could save the @@ERROR value and perform some kind of generic handler in your SP where you report the error to the client via RAISERROR.HTHDaniel Small MIAPwww.danielsmall.com IT Factoring |
 |
|
|
|
|
|