title: User does not have permission to alter database
body: <p>I am using MVC 4, Entity Framework 5, and the Code First approach.</p>
  <p>When I make changes to my model and run the application I get an error about not being able to drop the database because it is in use.</p>
  <p>To solve this, I've implemented my own <code>IDatabaseInitializer</code> to force a single connection like this:</p>
  <pre><code>public class ForceDropCreateDatabaseInitializer&lt;T&gt; : IDatabaseInitializer&lt;T&gt; where T : DbContext, new()
  {
      public ForceDropCreateDatabaseInitializer(Action&lt;T&gt; seed = null)
      {
          Seed = seed ?? delegate { };
      }
  
      public Action&lt;T&gt; Seed { get; set; }
  
      public void InitializeDatabase(T context)
      {
          if (context.Database.Exists())
          {
              string databaseName = context.Database.Connection.Database;
              string alterStatement = &quot;ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE&quot;;
              string dropStatement = &quot;USE [master] DROP DATABASE [{0}]&quot;;
  
              context.Database.ExecuteSqlCommand(alterStatement, databaseName);
              context.Database.ExecuteSqlCommand(dropStatement, databaseName);
          }
  
          context.Database.Create();
  
          Seed(context);
      }
  }
  </code></pre>
  <p>But now I am getting a permissions error on this line:</p>
  <p><code>context.Database.ExecuteSqlCommand(alterStatement, databaseName);</code></p>
  <p><strong>The exception message:</strong></p>
  <blockquote>
  <p>User does not have permission to alter database '@p0', the database does not exist, or the database is not in a state that allows access checks.</p>
  <p>ALTER DATABASE statement failed.</p>
  </blockquote>
  <p>I presume @p0 is used because I am using parameters.  How can I avoid this error and successfully drop and create my database each time I make model changes?</p>