title: PasswordSignInAsync tries to create new database
body: <p><br /> <br/></p>
  
  <p>I'm working on an existing project with Windows Authentification and existing database (so we are in database first for entity framework). <br />
  Now we are changing the authentification way for the OWIN Identity Authentication.
  <br /> <br /> <br />After following some tutorials, I got this new context for my asp identity tables: </p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("myconnexionstring", throwIfV1Schema: false)
      {
         Database.SetInitializer&lt;ApplicationDbContext&gt;(null);
      }
  
      protected override void OnModelCreating(DbModelBuilder builder)
      {
          base.OnModelCreating(builder);
          // Customize the ASP.NET Identity model and override the defaults if needed.
          // For example, you can rename the ASP.NET Identity table names and more.
          // Add your customizations after calling base.OnModelCreating(builder);
      }
  
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>
  
  <p>myconnexionstring is exactly the same as my original context generated by the EDMX in Database-first.</p>
  
  <p>I also turned the migrations enable thanks of the Package Manager Console and play a migration to create the asp identity tables in my database. No problem for this part.</p>
  
  <p>This is my StartupClass:</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          this.ConfigureAuth(app);
          app.MapSignalR();
      }
  
      public void ConfigureAuth(IAppBuilder app)
      {
          // Configure the db context, user manager and signin manager to use a single instance per request
          app.CreatePerOwinContext(ApplicationDbContext.Create);
          app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
          app.CreatePerOwinContext&lt;ApplicationSignInManager&gt;(ApplicationSignInManager.Create);
  
          // Enable the application to use a cookie to store information for the signed in user
          // and to use a cookie to temporarily store information about a user logging in with a third party login provider
          // Configure the sign in cookie
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/Login/LogOn"),
              CookieName = "MyCookie",
          });
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  
      }
  }
  </code></pre>
  
  <p>Now when I try to authenticate me, I get an exception with this message: CREATE DATABASE permission denied in database 'master'. This exception occurs when I call the <strong>PasswordSignInAsync</strong> method of my <strong>ApplicationSignInManager</strong></p>
  
  <p>This is my LoginController class:</p>
  
  <pre><code>public class LoginController : Controller
  {
      private ApplicationSignInManager _signInManager;
      public ApplicationSignInManager SignInManager
      {
          get
          {
              return _signInManager ?? HttpContext.GetOwinContext().Get&lt;ApplicationSignInManager&gt;();
          }
          private set { _signInManager = value; }
      }
  
      //
      // GET: /Account/Login
      [HttpGet]
      [AllowAnonymous]
      public ActionResult LogOn(string returnUrl = null)
      {
          ViewData["ReturnUrl"] = returnUrl;
          return View();
      }
  
      [HttpPost]
      [AllowAnonymous]
      public async Task&lt;ActionResult&gt; LogOn(LoginViewModel model, string returnUrl = null)
      {
          ViewData["ReturnUrl"] = returnUrl;
          if (ModelState.IsValid)
          {
              // the SqlException throw there 
              SignInStatus result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, false, false); 
              if (result == SignInStatus.Success)
              {
                  return RedirectToLocal(returnUrl);
              }
              else
              {
                  ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                  return View(model);
              }
          }
          else
          {
              ModelState.AddModelError(string.Empty, "Adress invalid");
              return View(model);
          }
      }
  
  
      private ActionResult RedirectToLocal(string returnUrl)
      {
          if (Url.IsLocalUrl(returnUrl))
          {
              return Redirect(returnUrl);
          }
          else
          {
              return RedirectToAction("Index", "Home");
          }
      }
  }
  </code></pre>
  
  <p>And this is my ApplicationSignInManager: </p>
  
  <pre><code> public class ApplicationSignInManager : SignInManager&lt;ApplicationUser, string&gt;
  {
      public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
      {
      }
  
      public override Task&lt;ClaimsIdentity&gt; CreateUserIdentityAsync(ApplicationUser user)
      {
          return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
      }
  
      public static ApplicationSignInManager Create(IdentityFactoryOptions&lt;ApplicationSignInManager&gt; options, IOwinContext context)
      {
          return new ApplicationSignInManager(context.GetUserManager&lt;ApplicationUserManager&gt;(), context.Authentication);
      }
  }
  </code></pre>
  
  <p>The ApplicationUserManager: </p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store)
          : base(store)
      {
      }
  
      public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context)
      {
          var manager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;());
          // Configure validation logic for usernames
          manager.UserValidator = new UserValidator&lt;ApplicationUser&gt;(manager)
          {
              AllowOnlyAlphanumericUserNames = false,
              RequireUniqueEmail = true
          };
  
          // Configure validation logic for passwords
          manager.PasswordValidator = new PasswordValidator
          {
              RequiredLength = 6,
              RequireNonLetterOrDigit = true,
              RequireDigit = true,
              RequireLowercase = true,
              RequireUppercase = true,
          };
  
          // Configure user lockout defaults
          manager.UserLockoutEnabledByDefault = true;
          manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
          manager.MaxFailedAccessAttemptsBeforeLockout = 5;
          //manager.EmailService = new EmailService();
  
          var dataProtectionProvider = options.DataProtectionProvider;
          if (dataProtectionProvider != null)
          {
              manager.UserTokenProvider =
                  new DataProtectorTokenProvider&lt;ApplicationUser&gt;(dataProtectionProvider.Create("ASP.NET Identity"));
          }
          return manager;
      }
  }
  </code></pre>
  
  <p>The ApplicationUser:</p>
  
  <pre><code>    public class ApplicationUser : IdentityUser
  {
      public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager)
      {
          // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
          var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
          // Add custom user claims here
          return userIdentity;
      }
  }
  </code></pre>
  
  <p><br /> <br />
  Any idea to help me ? It shouldn't try to create database but only sign the user in. </p>
  
  <p><br />
  <br />
  <strong>EDIT</strong></p>
  
  <p>The exception occurs the first time the database is called. 
  This is my connexion string: </p>
  
  <pre><code>&lt;add name="myconnexionstring" connectionString="metadata=res://*/DbModel.csdl|res://*/DbModel.ssdl|res://*/DbModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=localhost\SQLEXPRESS;initial catalog=Database2014;persist security info=True;user id=sa;password=MyPassword;multipleactiveresultsets=True;application name=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
  </code></pre>
  
  <p><br />
  <br /></p>
  
  <p><strong>EDIT 2</strong> <br /><br />
  My new connexion string</p>
  
  <pre><code>&lt;add name="myconnexionstringForIdentity" connectionString="data source=localhost\SQLEXPRESS;initial catalog=Database2014;persist security info=True;user id=sa;password=MyPassword;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>And I changed the ApplicationDbContext:</p>
  
  <pre><code>    public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("myconnexionstringForIdentity", throwIfV1Schema: false)
      {
         Database.SetInitializer&lt;ApplicationDbContext&gt;(null);
      }
  
      protected override void OnModelCreating(DbModelBuilder builder)
      {
          base.OnModelCreating(builder);
          // Customize the ASP.NET Identity model and override the defaults if needed.
          // For example, you can rename the ASP.NET Identity table names and more.
          // Add your customizations after calling base.OnModelCreating(builder);
      }
  
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>