System.InvalidOperationException: The transaction passed in is not associated with the current connection

Trying to do a routine

Update-Database -Verbose -ConnectionStringName MyStuffOnAzureProduction

but getting

---8<---

Using NuGet project 'YourStuff'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'yourstuff_db' (DataSource: tcp:yourstuff.database.windows.net,1433, Provider: System.Data.SqlClient, Origin: Explicit).
Applying explicit migrations: [201409300457248_add_seller_code_to_users].
Applying explicit migration: 201409300457248_add_seller_code_to_users.
System.InvalidOperationException: The transaction passed in is not associated with the current connection. Only transactions associated with the current connection may be used.
   at System.Data.Entity.Core.EntityClient.EntityConnection.UseStoreTransaction(DbTransaction storeTransaction)
   at System.Data.Entity.Infrastructure.CommitFailureHandler.BeganTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<BeginTransaction>b__2(IDbConnectionInterceptor i, DbConnection t, BeginTransactionInterceptionContext c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.BeginTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinNewTransaction(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass30.<ExecuteStatements>b__2e()
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The transaction passed in is not associated with the current connection. Only transactions associated with the current connection may be used

--->8---

I left the project untouched for three months, migrations to production were running fine. But now this... Googling didn't help at all.

Any hint?


February 6th, 2015 5:59am

Hello John,

Can you please check if the EF transaction is implemented using the steps mentioned in https://msdn.microsoft.com/en-us/data/dn456843.aspx

Regards,

Kumar Bijayanta

Free Windows Admin Tool Kit Click here and download it now
February 9th, 2015 3:33am

Hello Kumar,

thanks for your answer.

It's a tiny migration with no mention whatsoever of transactions in its code:

---8<---

Imports System Imports System.Data.Entity.Migrations Imports Microsoft.VisualBasic Namespace Migrations Public Partial Class add_seller_code_to_users_and_clubs Inherits DbMigration Public Overrides Sub Up() AddColumn("dbo.Users", "SellerCode", Function(c) c.String()) AddColumn("dbo.Clubs", "SellerCode", Function(c) c.String()) End Sub Public Overrides Sub Down() DropColumn("dbo.Clubs", "SellerCode") DropColumn("dbo.Users", "SellerCode") End Sub End Class End Namespace

--->8---

( https://gist.github.com/anonymous/5a3f4d07188faaee21a1 )

Kind regards,

John

February 9th, 2015 9:39pm

I was able to "bypass" the issue.

I commented out the SetTransactionHandler and the SetExecutionStrategy in my context configuration, as in:

https://gist.github.com/anonymous/8e90ed9f40f45b77331c

---8<---

Public Class MyStuffDbConfiguration
    Inherits DbConfiguration

    Public Sub New()

        MyBase.New()

        'SetTransactionHandler(
        '    "System.Data.SqlClient",
        '    Function() New System.Data.Entity.Infrastructure.CommitFailureHandler)

        'SetExecutionStrategy(
        '    "System.Data.SqlClient",
        '    Function() New System.Data.Entity.SqlServer.SqlAzureExecutionStrategy)
    End Sub
End Class

--->8---

And could execute my migration.

I'm going the switch them back in now...

Thanks anyway.

Free Windows Admin Tool Kit Click here and download it now
February 11th, 2015 11:05am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics