I created a new ASP.NET MVC 5 project in Visual Studio 2013 (Express for Web) and by default, the project uses LocalDb as its database, but how do you transfer or migrate the database to SQL Server?
I want to use SQL Server for the database instead of LocalDb. But how?
Click on the Create button and it will update the Index view as well add this new record to the database. Now let's go the SQL Server Object Explorer and refresh the database. Right-click on the Employees table and select the View data menu option. You will see that the record is added in the database.
Microsoft SQL Server Express LocalDB is a feature of SQL Server Express targeted to developers. It is available on SQL Server Express with Advanced Services. LocalDB installation copies a minimal set of files necessary to start the SQL Server Database Engine.
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.
Then go and hit Schema Compare option
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
Deselect all Delete actions for the target database, and leave selected all Add actions for the ASPNet DB, then hit Update button.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With