I am at a loss here.
Sub Main()
Dim sqlConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("db").ToString)
Dim dbCommand As New SqlCommand("test", sqlConnection)
dbCommand.CommandType = CommandType.StoredProcedure
Using ts As New TransactionScope
Using sqlConnection
sqlConnection.Open()
Try
dbCommand.ExecuteNonQuery()
Console.WriteLine("Success")
Catch ex As SqlException
Console.WriteLine(ex.Message)
Finally
dbCommand.Dispose()
End Try
ts.Complete()
End Using
End Using
Console.ReadKey()
End Sub
BEGIN
Insert dbo.Table_2
(Column1)
Values
(newid())
Insert dbo.Table_1
(Column1)
Values
('123456')
End
The Try block catches the exception in the second insert statement as it should, but I still get this exception "The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION." at the last End Using. I have tried placing Begin Transaction/Commit Transaction around the insert statement, but I get the same exception. What I am doing seems to match all the examples for the TransactionScope class.