transactionscope

Is there a way to use TransactionScope with an existing connection?

强颜欢笑 提交于 2019-12-17 19:27:21
问题 I have some code that works like the advised use of TransactionScope, but has an ambient connection instead of an ambient transaction. Is there a way to use a TransactionScope object with an existing connection, or is there an alternative in the .Net framework for this purpose? 回答1: In fact, there is one way. connection.EnlistTransaction(Transaction.Current) It works and it doesnt promote transaction to distributed if not necessary (contrary to what documentation says) HTH 回答2: To enlist a

“The operation is not valid for the state of the transaction” error and transaction scope

别说谁变了你拦得住时间么 提交于 2019-12-17 10:34:21
问题 I am getting the following error when I try to call a stored procedure that contains a SELECT Statement: The operation is not valid for the state of the transaction Here is the structure of my calls: public void MyAddUpdateMethod() { using (TransactionScope Scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { using(SQLServer Sql = new SQLServer(this.m_connstring)) { //do my first add update statement //do my call to the select statement sp bool DoesRecordExist = this

“The transaction has already been implicitly or explicitly committed or aborted” in transaction scope

坚强是说给别人听的谎言 提交于 2019-12-14 03:48:30
问题 I have a web server and two DB servers on two different networks, Db1 and Db2(Remote Database). DB1: SQL Server 2008 R2, operating system: Windows Server 2003 SP2 DB2: SQL Server 2000, operating system: Windows Server 2003 R2 Web server: Windows Server 2003 R2 I want to insert two different records in these databases and I'm using a TransactionScope . using (TransactionScope tscope = new TransactionScope(TransactionScopeOption.RequiresNew)) { //open connection db 1 //insert into db1 //open

Overriding SaveChangesAsync when enclosed inside TransactionScope?

走远了吗. 提交于 2019-12-13 20:11:54
问题 I'm fairly new to EF transactions, this is the code that is used for saving public bool Save(TbArea area, bool isNew, out string errMsg) { try { errMsg = string.Empty; using (var oScope = new System.Transactions.TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(120))) { try { TbArea oEntity = oContext.TbArea.Where(a => a.AreaCode == area.AreaCode && a.CompanyId == MainClass.SystemCompanyId).FirstOrDefault(); if (oEntity != null) { if (isNew) { errMsg = Resources.ResSales

NServiceBus - Problem with using TransactionScopeOption.Suppress in message handler

情到浓时终转凉″ 提交于 2019-12-13 19:10:14
问题 I have an endpoint that has a message handler which does some FTP work. Since the ftp process can take some time, I encapsulated the ftp method within a TransactionScope with TransactionScopeOption.Suppress to prevent the transaction timeout exceptions. Doing this got rid of the timeout exceptions, however the handler was fired 5 times (retries is set to 5 in my config file) The files were ftp'd ok, but they were just ftp'd 5 times. the handler look like it is re-fired after 10 or 11 minutes.

Entity Framework: Controlling db connection and specifying own transaction

自古美人都是妖i 提交于 2019-12-13 19:06:58
问题 I want to find a way to control EF's underlying db connection & transaction to make sure my application is using only one connection at a time during one transaction (I will need to support both Oracle and SQL Server). I found this good article which comes with a lot of recommendations, but brings up (like all the other articles I have read) the TransactionScope . Well, I would like to stay away of TransactionScope , if possible... Could I have a solution for this playing with only pure

entity framework 6 and pessimistic concurrency

坚强是说给别人听的谎言 提交于 2019-12-13 17:22:56
问题 I'm working on a project to gradually phase out a legacy application. In the proces, as a temporary solution we integrate with the legacy application using the database. The legacy application uses transactions with serializable isolation level. Because of database integration with a legacy application, i am for the moment best off using the same pessimistic concurrency model and serializable isolation level. These serialised transactions should not only be wrapped around the SaveChanges

TransactionScope error “ExecuteNonQuery requires an open and available Connection” in C# [duplicate]

☆樱花仙子☆ 提交于 2019-12-13 05:17:57
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: asp.Net TransactionScope error whenever I put TransactionScope, I got this error. ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. using (TransactionScope scope = new TransactionScope()) { ptDA.UpdateTC(InboundDS); ptDA.Addinventor(InboundDS); addressDA.AddAddress(InboundDS); scope.Complete(); } If I don't put the transaction scope , I don't get any error.

Volatile IEnlistmentNotification, TransactionScope.AsyncFlowEnabled = true and complex async/wait

孤街醉人 提交于 2019-12-13 05:16:28
问题 This is a followup question to the following question: Volatile IEnlistmentNotification and TransactionScope.AsyncFlowEnabled = true The approach accepted in the question above works as long as you don't await multiple statements. Let me show an example: public class SendResourceManager : IEnlistmentNotification { private readonly Action onCommit; public SendResourceManager(Action onCommit) { this.onCommit = onCommit; } public void Prepare(PreparingEnlistment preparingEnlistment) {

DTS transaction fails: Can not access a disposed object

谁说胖子不能爱 提交于 2019-12-13 04:28:07
问题 We are running distributed transactions, and on some rare occasions we get the following error: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SqlDelegatedTransaction'. at System.Data.SqlClient.SqlDelegatedTransaction.Rollback(SinglePhaseEnlistment enlistment) at System.Transactions.TransactionStateDelegatedAborting.EnterState(InternalTransaction tx) at System.Transactions.Transaction.Rollback() at System.Transactions.TransactionScope.InternalDispose() at