title: Set database collation in Entity Framework Code-First Initializer
body: <p>I want to set the default collation for a database, when Entity Framework Code First creates it.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>public class TestInitializer&lt;T&gt; : DropCreateDatabaseAlways&lt;T&gt; where T: DbContext
  {
      protected override void Seed(T context)
      {
          context.Database.ExecuteSqlCommand("ALTER DATABASE [Test] SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
          context.Database.ExecuteSqlCommand("ALTER DATABASE [Test] COLLATE Latin1_General_CI_AS");
          context.Database.ExecuteSqlCommand("ALTER DATABASE [Test] SET MULTI_USER");
      }
  }
  </code></pre>
  
  <p>This appears to run OK when SQL Server is <em>already</em> set to the same default collation Latin1_General_CI_AS.</p>
  
  <p>But if I specify a <em>different</em> collation, say SQL_Latin1_General_CP1_CI_AS this fails with the error,</p>
  
  <pre><code>System.Data.SqlClient.SqlException: Resetting the connection results in a different 
  state than the initial login. The login fails.
  </code></pre>
  
  <p>Can anyone advise how I can set the collation please?</p>