简体   繁体   中英

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?

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

在此处输入图片说明

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 )

Go to your project directory, Open the *.csproj file and add the below code under the Project tag.

<ItemGroup>
   <Content Include="App_Data\*">
      <CopyToPublishDirectory>always</CopyToPublishDirectory>
   </Content>
</ItemGroup>

Then publish again, all the files under App_Data folder will be uploaded to azure.

We can also update our Azure Db in VS: Tutorial: Build an ASP.NET app in Azure with SQL Database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM