EF6 migrations (LocalDb) update-database login failed

If you delete the DB file, it still stays registered with SqlLocalDB. If LocalDb gets hung up with can’t attach (after manually deleting the DB file) or Login failed see JSobell’s and CodingwithSpike’s answers here:

ef5-cannot-attach-the-file-0-as-database-1.

Run ‘sqllocaldb.exe stop v11.0’ and ‘sqllocaldb.exe delete v11.0’ from the PM Console

UPDATE:

Easier yet use SSMS. Server name: (local)\v11.0, Windows Authentication. This is really the best way to manage your localdb databases.


I'm working with VS 2013 and EF6.1 .

I got similar kind of error when I work with migration and delete database. I was unable to recreate database again. Found that error due to SQLExpress local database instance is running on background and keeping the deleted database connection with it.

following are the steps to handle this situation.

  1. Delete the database files (.mdf and .ldf) files.
  2. Delete Migration Folder from your application.
  3. Delete any database connection to that database from server Explorer data connections.
  4. Go to windows Command Prompt (IF VS 2012 or earlier you have to use the VS Command prompt).
  5. Run "sqllocaldb.exe stop v11.0" (This will stop the v11.0 service)
  6. Run "sqllocaldb.exe delete v11.0" (This will delete the v11.0 service)
  7. Go to Package Manager Console in Visual studio.
  8. Run "Enable-Migrations" (This will create Migration folder and content)
  9. Run "Add-Migration init" (This will scaffold the changes to next migration)
  10. Run "Update-Database" (This will create the database again)

I change Standard Security to Trusted Connection

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

in appsetting.json you can write this code

`{

  "ConnectionStrings": {
    "onlineStoreDB": "Server=.;Database=onlineStore;Trusted_Connection=True"
     },

    "Logging": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "AllowedHosts": "*"
  }`

It worked for me.