Results 1 to 3 of 3

Thread: "Zombie transaction"?

Threaded View

  1. #1

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    "Zombie transaction"?

    I'm not sure if this is the right thread but here goes. If I call on a SPROC from VB like so:

    Code:
                            dbCmd = New SqlCommand("spNewPatient", dbConn, dbTran)
                            dbCmd.CommandType = CommandType.StoredProcedure
                            For Each p As SqlParameter In _params
                                dbCmd.Parameters.Add(p)
                            Next
                            objPatientID = dbCmd.ExecuteScalar()
                            If objPatientID IsNot Nothing Then
                                intPatientID = CInt(objPatientID)
                            End If
                            dbTran.Commit()
    
                        Catch ex As Exception
                            MsgBox(ex.Message & strHelpDirections, MsgBoxStyle.Exclamation, errParsing)
                            Try
                                If Not dbTran.Connection Is Nothing Then
                                    dbTran.Rollback("trnAddProfile")
                                    dbTran.Dispose()
                                End If
                            Catch ex2 As SqlException
                                MsgBox("Failed to rollback changes. Please contact your system administrator." & vbCrLf & vbCrLf &
                                   "Exception Type: " & ex2.GetType().ToString(), MsgBoxStyle.Exclamation, "Rollback Failed")
                            End Try
    Do I need to have a Try-Catch block (for rollbacks) in my SPROC? I'm trying the code out, and deliberately making it fail, but it seems like the code still pulls through and doesn't rollback changes (evidenced by the increase in an Identity field).

    Code:
    	BEGIN TRY
    		BEGIN TRANSACTION AddPatient
    			INSERT INTO tblPatient (
    			... );
    			SELECT SCOPE_IDENTITY() AS PatientID;
    
    		COMMIT TRANSACTION
    	END TRY
    
    	BEGIN CATCH
    		ROLLBACK TRANSACTION AddPatient;
    	END CATCH
    END
    In addition, I'm getting a foreign key error if I use the code below instead of using the SQL code above:

    Code:
    ...
    --SELECT SCOPE_IDENTITY() AS PatientID;
    
    COMMIT TRANSACTION
    RETURN SCOPE_IDENTITY();
    Which is how I can see that there was an increase in the Identity field, however, the new entry was not created which leads me to believe that the transaction did rollback properly.
    Last edited by riechan; Apr 5th, 2016 at 04:55 AM.
    ====================
    ほんとにどもありがとう!

    Rie Ishida

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width