的TransactionScope [英] TransactionScope
问题描述
您好,谁能帮助我?如何在我有2个INSERT函数的情况下执行同步事务,但是一个依赖于另一个?
 
我有2个INSERT,First必须开始"插入文档,创建类型,编号,仓库
匹配" INSERT INTO documents_detail
如果我单独执行它们,它们可以正常工作
。我通过两个函数insertDocument()和insertDocumentDet()
insertDocument() =
" INSERT INTO documentos
insertDocumentDet() =
" INSERT INTO documentos_detalle
asi:
Public
Function facturarDocumentos()
尝试
使用 transScope
As
新
TransactionScope ()
使用 transScope2
As
新
TransactionScope ()
insertDocument()
insertDocumentDet()
结束
使用
transScope.Complete()
结束
使用
Catch ex As ApplicationException'( 交易被取消。)
MsgBox(ex.Message)
Catch ex
As
TransactionAbortedException
MsgBox(ex.Message)
结束
尝试
结束
功能
私人
Sub crear1_Click(发送者
As
Object ,e
As
EventArgs )
手柄 crear1.Click
'Totales()
facturarDocumentos()
结束
子
Las 功能 它们正确运行但最后 '( 交易已取消。)
您好,谁可以帮助我?我如何执行同步事务,其中我有2个INSERT函数,但是一个依赖于另一个?
一个事务在你的例子中,没有任何东西可以依赖于另一个作为交易。唯一可能依赖的是获取插入的父母的ID并将其应用于孩子的外键 当孩子$ b $时b被插入
事务范围将是父级和子级必须成功插入,否则,如果父级或父级子级无法插入,则回滚它们。 键强>
Hello, who can help me? How can I perform a synchronized transaction where I have 2 INSERT functions, but one depends on the other?
I have 2 INSERT the First must start "INSERT IN DOCUMENTS, to create type, number, warehouse
that matches "INSERT INTO documents_detail
If I execute them individually, they work correctly
. I am using them through two functions insertDocument () and insertDocumentDet ()
insertDocument() = "INSERT INTO documentos
insertDocumentDet() = "INSERT INTO documentos_detalle
asi:
Public Function facturarDocumentos()
Try
Using transScope As New TransactionScope()
Using transScope2 As New TransactionScope()
insertDocument()
insertDocumentDet()
End Using
transScope.Complete()
End Using
Catch ex As ApplicationException ‘ (The transaction was canceled.)
MsgBox(ex.Message)
Catch ex As TransactionAbortedException
MsgBox(ex.Message)
End Try
End Function
Private Sub crear1_Click(sender As Object, e As EventArgs) Handles crear1.Click
‘ Totales()
facturarDocumentos()
End Sub
Las Function they run correctly but at the end ‘ (The transaction was canceled.)
Hello, who can help me? How can I perform a synchronized transaction where I have 2 INSERT functions, but one depends on the other?
A transaction scope in your example there is nothing that depends upon the other as a transaction. The only thing that maybe is depended is taking the ID of the parent that is inserted and applying it to the child's foreign-key when the child is inserted
The transaction scope would be the parent and child must be inserted successfully, because otherwise, the parent or parent and child are rolled back if either one fails to insert.
这篇关于的TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!