I want to set my existing database TestDB into my application so that Identity will create their tables inside this database.
But I am getting error:
Cannot attach the file 'D:\TestApp\TestApp\App_Data\TestDB.mdf' as database 'TestDB'.
I have done couple of things which are
I removed
defaultconnectiontoTestDBConnectioninweb.config<add name="TestDBConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\TestDB.mdf;Initial Catalog=TestDB;Integrated Security=True" providerName="System.Data.SqlClient" />I changed in
IdentityModels.cspublic class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("TestDBConnection", throwIfV1Schema: false) { }In package Manager Console,
PM>enable-migrationsIn
Configuration.cs,internal sealed class Configuration : DbMigrationsConfiguration<TestApp.Models.ApplicationDbContext> { public Configuration() { AutomaticMigrationsEnabled = true; }
Please guide me where am I going wrong. I am looking for your suggestions.
<add name="TestDBConnection" connectionString="Data Source=LAPTOP-E06VT3CD\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True" providerName="System.Data.SqlClient" />and it worked for me now. Thank you