transactionscope

Refactoring ADO.NET - SqlTransaction vs. TransactionScope

六月ゝ 毕业季﹏ 提交于 2019-12-28 05:15:09
问题 I have "inherited" a little C# method that creates an ADO.NET SqlCommand object and loops over a list of items to be saved to the database (SQL Server 2005). Right now, the traditional SqlConnection/SqlCommand approach is used, and to make sure everything works, the two steps (delete old entries, then insert new ones) are wrapped into an ADO.NET SqlTransaction. using (SqlConnection _con = new SqlConnection(_connectionString)) { using (SqlTransaction _tran = _con.BeginTransaction()) { try {

Is this correct usage of TransactionSope?

时光毁灭记忆、已成空白 提交于 2019-12-25 14:22:28
问题 I have decided to try using a TransactionScope , rather than the SqlTransaction class. The following is my code, wrapped in a TransactionScope : using (var transaction = new System.Transactions.TransactionScope()) { using (MySqlCommand cmd = new MySqlCommand(sql, connection)) { if (listParameters != null && listParameters.Count > 0) { foreach (string currentKey in listParameters.Keys) { cmd.Parameters.Add(new MySqlParameter(currentKey, GetDictionaryValue(listParameters, currentKey))); } }

Entity Framework TransactionScope not rolling back

六眼飞鱼酱① 提交于 2019-12-25 06:32:03
问题 I've got a Publication table and a Receipt table. When I publish data out, I track it in the Publication table. When my test client receives that publication back from the broker, I track it in the Receipt table. My Publication table has a denormalized ReceiptCount column on it for ease of reporting. When my test consumer receives the Publication, the following code executes: try { using (var context = new PublicationVerifierEntities()) { using (var transaction = new TransactionScope()) { if

TransactionScope with IsolationLevel set to Serializable is locking all SQL SELECTs

*爱你&永不变心* 提交于 2019-12-25 04:55:26
问题 I'm using PowerShell transactions; which create a CommittableTransaction with an IsolationLevel of Serializable. The problem is that when I am executing a Transaction in this context all SELECTs are blocked on the tables affected by the transaction on any connection besides the one executing the transaction. I can perform gets from within the transaction but not anywhere else. This includes SSMS and other cmdlets executions. Is this expected behavior? Seems like I'm missing something... PS

Isolated ADO.NET connection and transaction within a transactionscope

♀尐吖头ヾ 提交于 2019-12-25 04:44:18
问题 Background: I have an ASP.NET MVC application that wraps controller actions in a TransactionScope using an Action Filter. Further downstream (in my infrastructure layer); I'd like to open up a new ADO.NET connection (to the same db as my outer TransactionScope, if that is relevent) and have it participate in its own transaction - without being tied to the current TransactionScope started at the controller level; how do I go about doing this? 回答1: You pass in TransactionScopeOption.RequiresNew

TransactionScope and Timeout Issue

不打扰是莪最后的温柔 提交于 2019-12-24 17:18:04
问题 We know that TransactionScope class can use user-defined timeout value. But timeout exception is thrown while exiting from the using {} block. How to throw this timeoutexception immediately after elapsed timeout value? 回答1: This is not possible. The TransactionScope simply stores the time that you started the transaction, then checks that time when committing the transaction. It has no way to throw an exception at any arbitrary point. In general, the only exception that can be thrown at any

TransactionScope and SQL Server Compact

北慕城南 提交于 2019-12-24 10:06:25
问题 SQL Server Compact doesn't support distributed transactions. So if there are more than one connection inside TransactionScope - the exception is thrown. Is there any way to setup ADO.NET provider to use one connection for the same connection string? I understand I can use usual transactions through connection.BeginTransaction but TransactionScope is preferable for me. UPDATE . Sorry, I didn't mention I work with Entity Framework, so I have no control on SQL Command. I may just pass connection

DocumentDb transactions as a part of an external transaction scope

ぃ、小莉子 提交于 2019-12-24 02:56:13
问题 Is there a way to make DocumentDb transactions part of an external transaction from C#? This is a follow-up question from here and failure in transaction 3 below should rollback any documentDb updates. using (var scope = new TransactionScope) { //first transaction //write to document db //third transaction } 回答1: I solved this by implementing IEnlistmentNotification on DocumentDbRepository interacting with DocumentDb n the following way - Implement the interface Make the current instance part

For a writeless transaction which is cheaper/quicker: COMMIT or ROLLBACK?

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:43:14
问题 I'm using sql transactions as containers for APPLOCKS and other concurrency mechanisms and so I sometimes create transactions at various isolation levels which only read data and don't write. I believe that in these situations, logically, COMMIT and ROLLBACK have identical outcomes. For performance reasons, I'd like to know which one is cheaper/quicker for the server to execute? Is unavoidable bookkeeping required that is optimized for the COMMIT case and additional overhead for ROLLBACK even

Using TransactionScope with System.Data.OracleClient - TransactionAbortedException

我的未来我决定 提交于 2019-12-24 01:53:22
问题 My system write some data to a SQL Server DB (2008), extracts it later and processes it some more, before writing it to an Oracle (10g) DB. I've wrapped my SQL Server interactions in a TransactionScope but when I try the same think with my Oracle interactions I get a `TranactionAbortedException - "The transaction has aborted". Remove the TransactionScope, and everything works OK. I could always revert back to manually managing my own transactions, but I'm hoping there is a simple solution.