Understanding how transaction.complete function?
c#, distributed-transactions
Solution
`TransactionScope.Complete` tells all of the Transaction Managers that they are good to commit this transaction. It is not a guarantee that everything will actually commit. After the Complete method is called all the transaction managers initiate a commit individually and if all of the transaction Managers succeed then the transaction is considered as completed successfully. You may refer to this link for further details
Problem
Hi All we have started to use transaction scope and below is the code snippet. What we need to understand is based on our understading after each of the using for connection the particular connection will be disposed/closed right? So since its closed how does the transaction.complete works? ``` using (TransactionScope transScope = new TransactionScope()) { try { string myConnStringLocal = "User Id=***;Password=****;Host=" + globalSettings.settingLocalIP + ";Database=" + globalSettings.settingLocalDB; using (MySqlConnection connectionLocal = new MySqlConnection(myConnStringLocal)) { try{ connectionLocal.Open(); } Catch(Exception e) { } finally{ connectionLocal.Close(); } } string myConnStringCentral = "User Id=***;Password=*****;Host=" + globalSettings.settingCentralIP + ";Database=" + globalSettings.settingCentralDB; using (MySqlConnection connectionCentral = new MySqlConnection(myConnStringCentral)) { try{ connectionCentral.Open(); } Catch(Exception e) { } finally{ connectionCentral.Close(); } } string myConnStringCentralCopy = "User Id=*****;Password=*****;Host=" + globalSettings.settingCentralCopyIP + ";Database=" + globalSettings.settingCentralCopyDB; using (MySqlConnection connectionCentralCopy = new MySqlConnection(myConnStringCentralCopy)) { try{ connectionCentralCopy.Open(); } Catch(Exception e) { } finally{ connectionCentralCopy.Close(); } } transScope.Complete(); Console.WriteLine("Transaction is completed"); } catch (Exception) { Console.WriteLine("Transaction is rolled back"); } } ```