07_05_GuyT
07_05_GuyT

Reputation: 2887

Switch DB From local SQL to AZURE DB with MVC5 App

I've Create MVC5 APP with Local DB like the following link(step 1 to 5) http://www.asp.net/mvc/tutorials/mvc-5/database-first-development/creating-the-web-application And the application is running as expected and now I need to change the DB from the sql Lite to azure DB ,I have created the same DB in azure (same data structure)and now what I want that the application use this DB ,There is simple way to do that ?

Im using VS2013 for web.

Upvotes: 0

Views: 1047

Answers (1)

Andrea Coluccio
Andrea Coluccio

Reputation: 836

Just change the "source" and "initial catalog" parameters of the connection string in the web.config file. Also, SQL Azure doesn't work with integrated security so you need to remove the "integrated security" parameter from the connection string and add the parameters "User ID" and "Password" with the credential of a user that you created in SQL Azure.

  • Open Visual Studio In Solution Explorer
  • find the file web.config
  • Look for the section connectionStrings

You should find something similar to:

<add name="testEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

You need to:

  • Replace (LocalDB)\v11.0 with the name of your server
  • Remove "attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;"
  • Add "Initial catalog=[name of your database in SQL Azure];user id=[name of your user id on SQL Azure];password=[your password]

Upvotes: 2

Related Questions