transactionscope

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

南笙酒味 提交于 2019-11-27 12:00:49
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.SelectStatementCall(id) } } } public bool SelectStatementCall(System.Guid id) { using(SQLServer Sql = new

NHibernate with TransactionScope

六月ゝ 毕业季﹏ 提交于 2019-11-27 11:54:54
Can anyone give me a quick overview of using TransactionScope with NHibernate? Do I need to do anything special with the session/IEnlistmentNotification/etc. to get this to work? Are there any pitfalls that I should worry about? For example, can I replace all of my hibernate transactions: var transaction = session.BeginTransaction(); try { // code transaction.Commit(); } catch (Exception) { transaction.Rollback(); } with this?: using (var scope = new TransactionScope()) { // code scope.Complete(); } I have been using nHibernate 2.1 for awhile, and after a few production issues and trying quite

Why doesn't TransactionScope work with Entity Framework?

北战南征 提交于 2019-11-27 11:07:07
问题 See the code below. If I initialize more than one entity context, then I get the following exception on the 2nd set of code only . If I comment out the second set it works. {"The underlying provider failed on Open."} Inner: {"Communication with the underlying transaction manager has failed."} Inner: {"Error HRESULT E_FAIL has been returned from a call to a COM component."} Note that this is a sample app and I know it doesn't make sense to create 2 contexts in a row. However, the production

TransactionScope Prematurely Completed

北慕城南 提交于 2019-11-27 10:04:58
问题 I have a block of code that runs within a TransactionScope and within this block of code I make several calls to the DB. Selects, Updates, Creates, and Deletes, the whole gamut. When I execute my delete I execute it using an extension method of the SqlCommand that will automatically resubmit the query if it deadlocks as this query could potentially hit a deadlock. I believe the problem occurs when a deadlock is hit and the function tries to resubmit the query. This is the error I receive: The

Nested/Child TransactionScope Rollback

五迷三道 提交于 2019-11-27 08:36:09
I am trying to nest TransactionScopes (.net 4.0) as you would nest Transactions in SQL Server, however it looks like they operate differently. I want my child transactions to be able to rollback if they fail, but allow the parent transaction to decide whether to commit/rollback the whole operation. The problem is when the first complete occurs, the transaction is rolled back. I realize that complete is different to commit. A greatly simplified example of what I am trying to do: static void Main(string[] args) { using(var scope = new TransactionScope()) // Trn A { // Insert Data A DoWork(true);

TransactionScope: Has it gotten better?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 07:53:56
问题 When TransactionScope first came out, I ran into some serious issues getting it to work between my dev machine (XP) and our database server (Windows Server 2003). When I looked into it more, this appeared to be a tricky and widespread issue that had a chance of becoming a headache in production, so I decided not to handle transactions this way (even though I like the syntax a lot and I really wanted it to work). Are these problems still out there or is this safe to use? Do you use this

NHibernate, transactions and TransactionScope

跟風遠走 提交于 2019-11-27 07:51:43
问题 I'm trying to find the best solution to handle transaction in a web application that uses NHibernate. We use a IHttpModule and at HttpApplication.BeginRequest we open a new session and we bind it to the HttpContext with ManagedWebSessionContext.Bind(context, session); We close and unbind the session on HttpApplication.EndRequest. In our Repository base class, we always wrapped a transaction around our SaveOrUpdate, Delete, Get methods like, according to best practice: public virtual void Save

Do Azure storage-related APIs participate in System.Transactions?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 06:59:19
问题 I can't find any information on this anywhere and yet the question is simple. Can I wrap storage-related actions in a TransactionScope such that e.g. if there is a rollback, the uploaded file is rolled back also? If the native APIs don't do this already, is there a public implementation anywhere? 回答1: If you're referring to Table or Blob updates, there's no notion of explicit commit or rollback. When you make an API call (whether direct REST call or via PowerShell / CLI / SDK), it's just an

Database.BeginTransaction vs Transactions.TransactionScope

假如想象 提交于 2019-11-27 06:24:19
What is the difference between System.Transactions.TransactionScope and EF6's Database.BeginTransaction ? Could someone give a small example or just explain which one to use when with a clear difference? P.S: In my project, I'm using EF6. I've already read the documentation but it didn't help much. Also looked up the examples but they are rather using SqlConnection.BeginTransaction and now MS has introduced this new Database.BeginTransaction in EF6. Flair I found out the answer in Entity Framework 6's documentation: With the introduction of EF6, Microsoft recommends to use new API methods:

Will an inner transaction scope roll back if the outer transaction scope doesn't complete?

落花浮王杯 提交于 2019-11-27 05:18:35
问题 I have two transaction scopes, one within another. I would love to know if the inner transaction scope will be rolled back after it has been committed and the outer one does not complete. 回答1: Since they are nested, the inner transaction will roll back. This is not the whole story, and depends on how you create the nested transaction, but by default, it will roll back. This article goes into depth about TransactionScope and should answer most of your questions. Being distributed or not is