|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ADO won't catch error while execute an Stored Procedure, Why?CREATE Procedure bh_RemoveProcedure ( @THEID uKey ) AS Delete From [T1] Where COL1 = @THEID And COL2 = 6 Delete From [T2] Where COL1 in (Select COL1 From [T3] Where COL2 = @THEID And COL3 = 6) Delete From [T2] Where COL1 = @THEID Delete From [T3] Where COL1 = @THEID And COL2 = 6 Delete From [T4] Where COL1 = @THEID GO It is executed in an transaction, before this [final] stored procedure is executed more stored procedure are executed. Because something was not cleaned up the last Delete statement Delete >From [T4] Where Col1 = @THEID failed, there is an relation between T4 and an other table.But in the vb code the error is not cached, so the function below here returns true... have someone any idea? In the Profiler I See the exception: SP:StmtCompleted -- bh_Remove... Delete From T3 Where COL1 = @THEID And COL2 = 6 Visual Basic 0 4 0 0 192 52 2005-11-04 1:24:29.423 SP:StmtStarting -- bh_Remove... Delete From [T4] Where COL1 = @THEID Visual Basic 192 52 2005-11-04 11:24:29.423 -----> Exception Error: 547, Severity: 16, State: 0 Visual Basic 192 52 2005-11-04 11:24:29.517 <---- SP:StmtCompleted -- bh_Remove... Delete From [T4] Where COL1 = @THEID Visual Basic 16 60 0 93 192 52 2005-11-04 11:24:29.423 SP:Completed exec bh_Remove... 2225 Visual Basic 93 192 52 2005-11-04 11:24:29.423 RPC:Completed exec bh_Remove... 2225 Visual Basic 16 80 0 93 192 52 2005-11-04 11:24:29.423 Vb Code: Friend Function TxRemoveThing(ByVal vsTHEIDID As String) As Boolean On Error GoTo ErrorHandler Dim cmdR As ADODB.Command Dim parID As ADODB.Parameter Set cmdR = New ADODB.Command Set cmdR.ActiveConnection = Me.Connection cmdR.CommandText = "bh_RemoveProcedure" cmdR.CommandType = adCmdStoredProc Set parID = cmdR.CreateParameter("THEID", KeyDType, adParamInput) cmdR.Parameters.Append parID parID.Value = vsRoleID cmdR.Execute TxRemoveRole = True Set cmdR = Nothing Set parID= Nothing Exit Function ErrorHandler: TxRemoveRole = False Set cmdR = Nothing Set parID= Nothing RaiseError Err.Number, MODULENAME & ":TxRemoveRole", Err.Description End Function I Found the sollution:
I Changed the Vb code to : Friend Function TxRemoveThing(ByVal vsTHEIDID As String) As Boolean On Error GoTo ErrorHandler Dim cmdR As ADODB.Command Dim parID As ADODB.Parameter Dim rs As ADODB.Recordset Set cmdR = New ADODB.Command Set cmdR.ActiveConnection = Me.Connection cmdR.CommandText = "bh_RemoveProcedure" cmdR.CommandType = adCmdStoredProc Set parID = cmdR.CreateParameter("THEID", KeyDType, adParamInput) cmdR.Parameters.Append parID parID.Value = vsRoleID '--> CHANGED: Set rs = cmdR.Execute 'For each Delete statement an recordset is returnd which cotains the error for each statement, While Not rs Is Nothing Set rs = rs.NextRecordset Wend '--> END TxRemoveRole = True Set cmdR = Nothing Set parID= Nothing Exit Function ErrorHandler: TxRemoveRole = False Set cmdR = Nothing Set parID= Nothing RaiseError Err.Number, MODULENAME & ":TxRemoveRole", Err.Description Bas schreef: Show quote > If have created an stored procedure like : > > CREATE Procedure bh_RemoveProcedure > ( > @THEID uKey > ) > > AS > > Delete > From [T1] > Where COL1 = @THEID > And COL2 = 6 > > Delete > From [T2] > Where COL1 in > (Select COL1 > From [T3] > Where COL2 = @THEID > And COL3 = 6) > > Delete > From [T2] > Where COL1 = @THEID > > Delete > From [T3] > Where COL1 = @THEID > And COL2 = 6 > > > Delete > From [T4] > Where COL1 = @THEID > > GO > > It is executed in an transaction, before this [final] stored procedure > is executed more stored procedure are executed. > Because something was not cleaned up the last Delete statement Delete > >From [T4] Where Col1 = @THEID failed, there is an relation between T4 > and an other table. > > But in the vb code the error is not cached, so the function below here > returns true... have someone any idea? > > In the Profiler I See the exception: > SP:StmtCompleted -- bh_Remove... Delete From T3 Where COL1 = @THEID And > COL2 = 6 Visual Basic 0 4 0 0 192 52 2005-11-04 1:24:29.423 > > SP:StmtStarting -- bh_Remove... Delete From [T4] Where COL1 = @THEID > Visual Basic 192 52 2005-11-04 11:24:29.423 > > -----> Exception Error: 547, Severity: 16, State: 0 Visual > Basic 192 52 2005-11-04 11:24:29.517 <---- > > SP:StmtCompleted -- bh_Remove... Delete From [T4] Where COL1 = > @THEID Visual Basic 16 60 0 93 192 52 2005-11-04 11:24:29.423 > > SP:Completed exec bh_Remove... 2225 Visual Basic 93 192 52 2005-11-04 > 11:24:29.423 > > RPC:Completed exec bh_Remove... 2225 Visual > Basic 16 80 0 93 192 52 2005-11-04 11:24:29.423 > > Vb Code: > > Friend Function TxRemoveThing(ByVal vsTHEIDID As String) As Boolean > On Error GoTo ErrorHandler > Dim cmdR As ADODB.Command > Dim parID As ADODB.Parameter > > Set cmdR = New ADODB.Command > > Set cmdR.ActiveConnection = Me.Connection > cmdR.CommandText = "bh_RemoveProcedure" > cmdR.CommandType = adCmdStoredProc > > Set parID = cmdR.CreateParameter("THEID", KeyDType, adParamInput) > cmdR.Parameters.Append parID > parID.Value = vsRoleID > > cmdR.Execute > > TxRemoveRole = True > Set cmdR = Nothing > Set parID= Nothing > Exit Function > > ErrorHandler: > TxRemoveRole = False > Set cmdR = Nothing > Set parID= Nothing > RaiseError Err.Number, MODULENAME & ":TxRemoveRole", > Err.Description > > End Function It's best to handle errors where they happen - on the server.
Read more on error-handling in T-SQL here: http://www.sommarskog.se/ ML |
|||||||||||||||||||||||