How to transfer ASP.NET MVC Database from LocalDb to SQL Server? How to transfer ASP.NET MVC Database from LocalDb to SQL Server? sql-server sql-server

How to transfer ASP.NET MVC Database from LocalDb to SQL Server?


Notwithstanding this question is old, the answer didn't help me so I want to share how I solved it for my self.

On Server Explorer, find your ASPNet DB. Then open it using SQL Server Object Explorer.

enter image description here

Then go and hit Schema Compare option

Compare Schemas

Then on the the Schema Compare window for the Target database, select the SQL Server data base you want the ASPNet DB to integrate to. Then hit Compare button

Set Options

Deselect all Delete actions for the target database, and leave selected all Add actions for the ASPNet DB, then hit Update button.

Update

Finally, update your connection string so it points to your SQL Server DB


Got it!

Based on @warheat1990's answer, you just have to change the connection string. But @warheat1990's answer had a little too much change. So here's my original (LocalDb) connection string:

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

To connect it to SQL Server instead of LocalDB, I modified the connection string into:

<add name="DefaultConnection"     connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=my_project;Integrated Security=True"     providerName="System.Data.SqlClient"/>

Thanks to @warheat1990 for the idea of simply changing the Web.config. My first thoughts were to identify and use the feature that VS supplies, if theres any. Because Microsoft doesnt have a concise documentation on how to do this.


Change the connectionString in your web.config

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

to your own database connectionString, for example :

  <connectionStrings>    <add name="DefaultConnection" connectionString="Data Source=7.7.7.7\sql;Initial Catalog=TestDB;User ID=sa;Password=sa" />  </connectionStrings>