Search code examples
asp.net.netazuredeploymentwebdeploy

Deploy ASP MVC application with existing database on Azure


I have database define in App_Data folder. Is it possible to deploy my app with database included App_Data if folder? Or update azure db automatically? Or if it isn't possible what's the best way to update azure db manually?


Solution

  • first solution for you

    if you work with the entity framework, you can do the direct update, in the first step you have to replace the DB connection string in Web.config:

     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=OnlineAuctionDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OnlineAuctionDb.mdf" providerName="System.Data.SqlClient"/>
    

    by connection string of database in azure

    <add name="DefaultConnection" connectionString="Data Source=xxxxxxx.database.windows.net,1433;Initial Catalog=database;User Id=user@xxxxxxxx.database.windows.net;Password=mypassword" providerName="System.Data.SqlClient"/>
    

    after if you publish check this value "selected Run the code First Migrations" as you see in this picture

    enter image description here

    In the last step, you click on the Publish button

    Second solution for you

    you should get the SQL script from your local database and run it on your remote database . (don't forgot to change connection string in your web.config for test before publish )