title: Code first custom SQL migration timeout exception
body: <p>I am trying to create FULL TEXT index using Entity Framework Migration by executing custom Sql.</p>
  
  <p>My migration class looks like this:</p>
  
  <pre><code>public partial class DocumentContentFullTextIndex : DbMigration
  {
      public override void Up()
      {
          AlterColumn("dbo.Attachments", "ContentType", c =&gt; c.String(maxLength: 260));
  
          Sql("CREATE FULLTEXT CATALOG FullTextIndexes AS DEFAULT;", true);
  
          Sql(@"CREATE FULLTEXT INDEX ON [Attachments](
  Content
      TYPE COLUMN ContentType
      Language 'ENGLISH'
  )
  KEY INDEX [PK_dbo.Attachments]
  ON FullTextIndexes;", true);
      }
  
      public override void Down()
      {
          AlterColumn("dbo.Attachments", "ContentType", c =&gt; c.String(maxLength: null));
  
          Sql("DROP FULLTEXT INDEX ON [Attachments]");
          Sql("DROP FULLTEXT CATALOG FullTextIndexes");
      }
  }
  </code></pre>
  
  <p>When I run it from MSSQL management studio everything is perfect and SQL did exactly what I am expected from it.</p>
  
  <p>But when running from migration project second Sql request fires exception</p>
  
  <blockquote>
    <p>Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.</p>
  </blockquote>
  
  <p>Full stack trace with -Verbose flag:</p>
  
  <pre><code>Update-Database -ConnectionStringName DatabaseContext -Verbose
  Using StartUp project 'Lx2'.
  Using NuGet project 'Database.Model'.
  Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
  Target database is: 'Lx2' (DataSource: ., Provider: System.Data.SqlClient, Origin: Explicit).
  Applying explicit migrations: [201406050348083_AttachmentsContentFullTextIndex].
  Applying explicit migration: 201406050348083_AttachmentsContentFullTextIndex.
  ALTER TABLE [dbo].[Attachments] ALTER COLUMN [ContentType] [nvarchar](260) NULL
  CREATE FULLTEXT CATALOG FullTextIndexes AS DEFAULT;
  CREATE FULLTEXT INDEX ON [Attachments](
  Content
      TYPE COLUMN ContentType
      Language 'ENGLISH'
  )
  KEY INDEX [PK_dbo.Attachments]
  ON FullTextIndexes;
  System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---&gt; System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
  
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
     at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.&lt;NonQuery&gt;b__0(DbCommand t, DbCommandInterceptionContext`1 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.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
     at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
     at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext)
     at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext)
     at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
     at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
     at System.Data.Entity.Migrations.DbMigrator.&lt;&gt;c__DisplayClass30.&lt;ExecuteStatements&gt;b__2e()
     at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.&lt;&gt;c__DisplayClass1.&lt;Execute&gt;b__0()
     at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
     at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.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, XDocument 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.&lt;&gt;c__DisplayClassc.&lt;Update&gt;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.&lt;&gt;c__DisplayClass2.&lt;.ctor&gt;b__0()
     at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
  ClientConnectionId:3d298f0a-e2dc-4976-8587-c69d03b23c6b
  Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
  </code></pre>
  
  <p>I tried to copy all SQL from Verbose output exactly 'as is' and execute it directly in Management Studio and it work exactly as expected with no errors.</p>
  
  <p>Any ideas how this can be fixed?</p>
  
  <p>Strange thing also that if I put ContentType max length changing code</p>
  
  <pre><code>AlterColumn("dbo.Attachments", "ContentType", c =&gt; c.String(maxLength: 260));
  </code></pre>
  
  <p>in separate migration file everything also works fine.</p>
  
  <h2>UPDATE:</h2>
  
  <p>After <a href="https://stackoverflow.com/users/2248845/shivakumar">shivakumar</a> advice I tried to increase connection timeout (up to 5 minutes) in migration configuration and this increased time before I received "Timeout exception" but problem is still there.</p>