使用SQL事务出错 代码如下:
Using Trans As SqlTransaction = con.BeginTransaction()
Dim cmd As SqlCommand = con.CreateCommand
cmd.Transaction = Trans
For I As Integer = 0 To 1
cmd.CommandText = "create table TT(F1 int,F2 int)"
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
End Try
Next
Trans.Commit() ‘运行到此,错误提示:此 SqlTransaction 已完成;它再也无法使用
End Using
请问这是为什么?怎么解决呢? ------解决方案-------------------- Transaction开始了吗? ------解决方案-------------------- Using Trans As SqlTransaction = con.BeginTransaction() 这句话就表明已经开始了, ------解决方案-------------------- 1 确认con已经打开