개발관련/C#
Syste.transaction 사용법[출처 : msdn]
후니의 개발이야기
2008. 1. 10. 12:25
728x90
반응형
블로그로도 수익을 창출할 수 있다는 것을 아시나요? 이 블로그는 매달 200$ 이상의 수입을 애드센스 광고수입으로 벌어들입니다.
|
|
System.Transactions를 사용하려면 System.Transactions.dll에 대한 참조가 필요합니다.
Visual Basic | |
---|---|
Using transScope As New TransactionScope() Using connection1 As New SqlConnection(connectString1) ' Opening connection1 automatically enlists it in the ' TransactionScope as a lightweight transaction. connection1.Open() ' Do work in the first connection. ' Assumes conditional logic in place where the second ' connection will only be opened as needed. Using connection2 As New SqlConnection(connectString2) ' Open the second connection, which enlists the ' second connection and promotes the transaction to ' a full distributed transaction. connection2.Open() ' Do work in the second connection. End Using End Using ' Commit the transaction. transScope.Complete() End Using |
C# | |
---|---|
using (TransactionScope transScope = new TransactionScope()) { using (SqlConnection connection1 = new SqlConnection(connectString1)) { // Opening connection1 automatically enlists it in the // TransactionScope as a lightweight transaction. connection1.Open(); // Do work in the first connection. // Assumes conditional logic in place where the second // connection will only be opened as needed. using (SqlConnection connection2 = new SqlConnection(connectString2)) { // Open the second connection, which enlists the // second connection and promotes the transaction to // a full distributed transaction. connection2.Open(); // Do work in the second connection. } } // The Complete method commits the transaction. transScope.Complete(); } |
728x90
반응형