hi!
i want to ask about the transaction
i want to rollback the changes if something goes wrong either in the clients site(internet connection failed in the time the sub is running) or in the servers side(if the server falls)
is the sqltrasnsaction the properly solution??
i found this example for the sqltransaction
Code:Dim thisConnection As New SqlConnection("server=(local)\SQLEXPRESS;" & _ "integrated security=sspi;database=MyDatabase") ' SQL Delete Commands Dim sql As String = "DELETE FROM Employee " & _ "WHERE ID = 10" ' Create command Dim thisCommand As New SqlCommand(sql, thisConnection) ' Create Transaction Dim thisTransaction As SqlTransaction Try ' Open Connection thisConnection.Open() ' Begin transaction and attach it to command thisTransaction = thisConnection.BeginTransaction() thisCommand.Transaction = thisTransaction ' Run delete command thisCommand.ExecuteNonQuery() ' Commit transaction thisTransaction.Commit() ' Display success Console.WriteLine("Transaction Committed. Data Deleted") Catch ex As Exception ' Roll back transaction thisTransaction.Rollback() Console.WriteLine("Transaction rolled back : " & ex.Message) Finally ' Close Connection thisConnection.Close() End Try




Reply With Quote