4

I currently started a new project in Visual Studio 2013 with ASP.NET MVC5 using Entity Framework Model-First. With entity is all fine, by now... haha

My question is: There's any way to change the database of Identity without overwriting it?

Explaining better: Currently, my database generated from Entity is well in my external SQL Server database, but my account information is in (I guess it) the SQL Server that run with Visual Studio 2013.

Reinforcing it: I just want to change the database to be the same as my Entity Framework is using, I don't want to overwrite it. Is it possible?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Wellington Zanelli
  • 1,894
  • 3
  • 18
  • 43

1 Answers1

8

You have to change the ConnectionString to point to the database that you want. Identity uses EF to create the database and schema. Alternatively you can pass in the ConnectionString of your EF database to the IdentityDbContext. For example, in this sample, DefaultConnection is the name of the ConnectionString used by my EF Context and Identity Context:

public class MyDbContext : IdentityDbContext<ApplicationUser>
    {
        public MyDbContext()
            : base("DefaultConnection")
        {
        }
    }
ataravati
  • 8,891
  • 9
  • 57
  • 89
pranav rastogi
  • 4,124
  • 23
  • 23
  • Thanks a lot! It's worked. Btw, I've tested it with MySql too but in this case the tables aren't automatic generated, do you know why? If I create the tables, I can access the data. – Wellington Zanelli Jun 24 '14 at 19:46
  • @WellingtonZanelli not worked for me! its cause error on sqlserver 2016 vs2015! :( – Hamid Nov 02 '17 at 14:17