<p><strong>Scenario:</strong> C# apps uses SQL2000. It excecute 3 stored procs within a try catch in the app. In the catch the error is suppressed. Due to some legalities, the c# code cannot be changed and implemented. </p>

<p><strong>Q:</strong> How do I trap the actual SQL error in the stored proc into a log file or other table? @@Error returns an error message to the app but when evaluated in query analyzer it is always 0 although the 'If @@Error &lt;> 0' does fire. I try to store the @@Error number, but it is always 0.</p>

<p>Please help.</p>

Haven't got an example to hand, but look at using
```
```
RAISERROR ... WITH LOG
```
```
see:
http://msdn.microsoft.com/en-us/library/aa238452(SQL.80).aspx
for more on this.
Or use:
```
```
xp_logevent {error_number, 'message'} [, 'severity']
```
```
to write to the event log.  More details at
http://msdn.microsoft.com/en-us/library/aa260695(SQL.80).aspx