问题描述
您好,谁能帮助我?如何在我有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 功能 它们正确运行但最后 '( 交易已取消。)
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:
PublicFunction facturarDocumentos()
Try
Using transScopeAsNewTransactionScope()
Using transScope2AsNewTransactionScope()
insertDocument()
insertDocumentDet()
EndUsing
transScope.Complete()
EndUsing
Catch ex As ApplicationException ‘ (The transaction was canceled.)
MsgBox(ex.Message)
Catch exAsTransactionAbortedException
MsgBox(ex.Message)
EndTry
EndFunction
PrivateSub crear1_Click(senderAsObject, eAsEventArgs)Handles crear1.Click
‘ Totales()
facturarDocumentos()
EndSub
Las Function they run correctly but at the end ‘ (The transaction was canceled.)
这篇关于的TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!