문제

Is it possible to change the IdentityUser to use a SQL Server 2012 database instead of the localdb that installs by default when creating a new ASP.NET Web Application?

I have an existing SQL Server 2012 database which I would like to use with the MVC 5 project, I can modify the connection string in the web config, however I get the error "The entity type ApplicationUser is not part of the model for the current context".

I've can't find any reference to AspNetUsers to that I can substitute for my User table.

Am I forced to modify the existing localdb and rewrite my previous database to work with the new AspNet table structure and if so can the database then be migrated and upscaled to SQL Server 2012?

Any assistance would be much appreciated :-)

도움이 되었습니까?

해결책 2

Solved this by closing Visual Studio 2013 and locating the path of the localdb which was WebApplication1\App_Data, there were two files aspnet-WebApplication1-20140430012043.mdf and aspnet-WebApplication1-20140430012043_log.ldf residing in that folder.

I modified the security permissions of WebApplication1\App_Data so that SQL Server 2012 would have no issues connecting to it.

I then opened Microsoft SQL Server Management Studio and proceeded to attach the database, once the database was attached to the instance, I backed the database up. Next I dropped the database and carried out a restore, this time renaming the database as per the project and relocating the mdf and ldf files.

I then opened my project in Visual Studio 2013 and modified the Web.config from:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20140430012043.mdf;Initial Catalog=aspnet-WebApplication1-20140430012043;Integrated Security=True"
  providerName="System.Data.SqlClient" />
</connectionStrings>

to:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=MYSERVER;Initial Catalog=WebApplication1;Integrated Security=True" providerName="System.Data.SqlClient" />

Ran the project and all is well.

다른 팁

Simply enable migrations for your project (assuming VS2013 - newer versions are different and don't require migrations to be enabled for vNext) 1. Enable-Migrations 2. Update-Database -Script -SourceMigration: $InitialDatabase

That will generate the scripts you need.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top