繁体   English   中英

从vs2013在Azure中创建数据库

[英]Create DB in azure from vs2013

我按照本教程的步骤1-5进行操作,并在本地对其进行了检查,以及它的正常工作http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started现在,我将解决方案转换为Azure并将其发布而且我能够看到Asp页面,但是当我导航到电影(在URL中)时出现错误,我想这与数据库有关,在app数据文件夹中,我有本地数据库,有一种方法将其转换为azure数据库或存储 ,以便能够从azure url而不是从本地更新数据?

最好的方法是创建一个Azure SQL数据库 请注意,在本教程中,您可能可以在步骤4处停止,因为EF Code First将负责生成模式。

然后,您需要将Web.config转换设置为Web.Debug.config和Web.Release.config文件,并且Visual Studio将在部署时自动更改您的连接字符串。

在您的Web.config中,找到您的连接字符串:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

(请注意,如果使用SQL Express或其他方法,您的实际连接字符串可能会有所不同)

然后将以下内容添加到Web.Debug.config和Web.Release.config中:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Server={the connection string from the Azure portal}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

确保连接字符串名称与Web.config中的名称相同,以便它知道要替换的字符串。

现在,当您在本地运行项目时,它将连接到本地数据库。 当您部署到Azure时,它将连接到Azure SQL数据库。

暂无
暂无

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

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