简体   繁体   English

在Azure上使用现有数据库部署ASP MVC应用程序

[英]Deploy ASP MVC application with existing database on Azure

I have database define in App_Data folder. 我在App_Data文件夹中定义了数据库。 Is it possible to deploy my app with database included App_Data if folder? 如果使用文件夹,是否可以部署包含数据库App_Data的应用程序? Or update azure db automatically? 还是自动更新azure db? Or if it isn't possible what's the best way to update azure db manually? 或者,如果不可能,手动更新azure db的最佳方法是什么?

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: 如果您使用实体框架,则可以进行直接更新,第一步,您必须替换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 . 您应该从本地数据库获取SQL脚本,然后在远程数据库上运行它。 (don't forgot to change connection string in your web.config for test before publish ) (发布前不要忘记更改web.config中的连接字符串以进行测试)

Go to your project directory, Open the *.csproj file and add the below code under the Project tag. 转到您的项目目录,打开* .csproj文件,并将以下代码添加到Project标记下。

<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. 然后再次发布,App_Data文件夹下的所有文件都将上传到azure。

We can also update our Azure Db in VS: Tutorial: Build an ASP.NET app in Azure with SQL Database 我们还可以在VS中更新Azure DB: 教程:使用SQL数据库在Azure中构建ASP.NET应用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用数据库部署ASP.NET MVC 4应用程序? - How to deploy an asp.net mvc 4 application with database? 将Azure数据库连接到现有的Asp.Net Web应用程序 - Connect Azure database to existing Asp.Net web application 如何将 ASP.NET Web 应用程序部署到 Azure 与现有的 Z9778840A0104CB30C52ZB7 服务器数据库 (76410CB30C52ZB7) 服务器数据库 - How to deploy an ASP.NET Web App to Azure with an existing SQL Server database (Azure Data Studio) 将ASP.NET Web项目上的现有数据从Visual Studio中的本地数据库部署到Azure数据库 - Deploy existing data on ASP.NET web project from local database in Visual Studio to Azure database 使用ASP.NET MVC应用程序定期插入Azure数据库 - Periodically insertion into Azure database with ASP.NET MVC application 如何将带有devexpress组件的ASP.NET MVC应用程序部署到Azure网站 - How to deploy ASP.NET MVC application with devexpress components to Azure websites ASP.NET MVC - 如何首先使用实体框架模型/数据库部署到 Azure? - ASP.NET MVC - How to Deploy to Azure using Entity Framework Model/Database First? 部署在Azure上使用ACS的MVC应用程序 - Deploy MVC application that uses ACS on Azure 如何在现有的Azure MVC ASP.NET Web应用程序上启用“云中的主机” - How to enable “host in the cloud” on existing Azure MVC ASP.NET web application 使用Azure数据库(ASP.NET MVC) - Use Azure Database (ASP.NET MVC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM