1

I have created new project under MVC5 with individual authentication. Then I have build it and register a test user to test login system. I already migrated my database table LocalDB to my SQL server.

Now created connection string to connect SQL server but the problem is it is still using my old LocalDB which saving data to App_Data folder.

Can you give me some advice to switch this LocalDB to my SQL server? I already created "ADO.NET Entity Data Model" but how to connect it with my SQL server? Any idea? Any question welcome.

3
  • 1
    You created a connection string for your sql server, but are you using it? Simply remove all references to your localDB from your config and see what happens - likely you cannot connect at all to a database. For the rest, we can't see from here how you (try to) connect to anything, so we can;t see what could be wrong without you showing what you tried... Commented Aug 12, 2017 at 15:03
  • @oerkelens you are correct. i have commented out all of my 2 connection string form Web.Config but then i still can login with my test user which i was created on starting! isn't it strange? Commented Aug 12, 2017 at 15:05
  • You said you migrated your database from LocalDB to your SQL Server, that would bring over your "test user" with it. Commented Mar 1, 2019 at 15:40

1 Answer 1

-1

This Guide was very useful for me :

https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/

Follow all the easy steps for move your LocalDB table to SQL server db Table.

1. Inspect the Web.config File Connection String and Connect to Local Database

Change the defaut connection string:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApp-20190226025646.mdf;Initial Catalog=aspnet-WebApp-20190226025646;Integrated Security=True" providerName="System.Data.SqlClient" />

To your connection string:

<add name="DefaultConnection" connectionString="Data Source=PC-YWGSB;Initial Catalog=WebApp;user id=admin;password=admin" providerName="System.Data.SqlClient" />

2. Then use the commands for DB Migration "Codefirst"

This is the official guide:

https://learn.microsoft.com/it-it/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

From the Tools menu, select NuGet Package Manager > Package Manager Console. At the PM> prompt enter the following commands:

  1. enable-migrations
  2. add-migration InitialCreate
  3. update-database

The database will be created automatically during migration. If you already have one make sure to backup all tables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.