We have a .NET application (VB / VS2010) and many stored procedures are called on SQL Server 2008 to query the database. We also have quite a few update / insert / delete triggers that are executed automatically as soon as these stored procedures modify the database tables.
Often there are situations when a stored procedure is called, and it seems to work fine, since the error does not occur, and the .NET application continues to work as usual. However, if I then look under the covers and make a call to the stored procedure manually through the SQL Server client, I see that the trigger, which is executed immediately after the stored procedure failed, discards all changes.
So my question is: what is the best way to detect and go through errors in our .NET β stored procedure β trigger script to know exactly in a .NET application that everything worked or not in case of an error?
Thanks a lot in advance, Steve
Update: now I am at home and away from my desk (and code base) for the weekend, so you will not have the opportunity to check the very details of stored procedures. Thank you very much for the answers that have been given so far. I can take a look at the code again next week.
But in the meantime ...
Question about MS SQL Server version: this is 2008.
From what I know from my head, we call stored procedures (at least those that do not read data and βjustβ update, delete, or insert data) as follows:
Using connection As New SqlConnection("connectionString")
Dim command As New SqlCommand("EXEC STORED_PROCEDUR_ENAME), connection)
command.Connection.Open()
command.ExecuteNonQuery()
End Using
, , , - , - ,
command.ExecuteNonQuery()
. , ?
, ExecuteDataReader, , , ...
SQL, .