[英]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.