ADO.NET Series Quiz 2 About distributed transactions.

xiaoxiao2021-03-06  58

Problem: About Distributed Transactions: Database A and Database B have a Bank table (actual situation A and B, different types of database (support DTC)) table structure, BankAccount, Amounta Database Record: A 1000b database Data B 1000 For testing, it is not tested in Web Service in the Web Service in order to test. The code is as follows: _ public function DTSTEST () AS String Try ContextUtil.NableCommit ()

DrawMoneyFroma (100) DepostMoneyTob (100) ContextUtil.setComplete () Return "OK!" Catch exception contextutil.Setabort () Return "failed" ex.Message End Try

END FUNCTION

Public Sub DrawMoneyFroma (Byval Amount As Long) extracts a certain amount of money from A. New SqlConnection ("Server = Server1; Database = a; uid = sa; pwd = password @ 1; enlist = false") CNN.Open () DIM CMD AS New Sqlcommand ("Update Bank Set Amount = Amount -" & Amount & "Where BankAcount = 'a'", CNN) cmd.executenonQuery ()

End Sub

PUBLIC SUB DepostMoneyTOB (BYVAL AMOUNT AS Long) Add a certain amount of money DIM CNN AS New SqlConnection ("Server = Server2; Database = B; PWD = Password @ 1; UID = SA; Enlist = False") CNN.Open () DIM CMD AS New Sqlcommand ("Update Bank Set Amount = Amount " & Amount & "Where BankAcount = '" "CMD.EXECUTENONQUERY () End Sub then calls Web Service It is found that the balance of A is 900, while the account of B is still 1000, distributed transactions fail. What is the possible reason? Similarly, the above code is as long as it is slightly modified.

转载请注明原文地址:https://www.9cbs.com/read-114253.html

New Post(0)