1. 首先你需要添加一个程序包到你的ASP.NET项目中。右键点击你的ASP项目,选择Add Library Package Reference:
注意:这里的MigrateASPWebsiteAzure只是一个例子,请在Visual Studio中选择你将要配置的ASP.NET项目。
2. 在打开的对话中,搜索"Microsoft.AspNet.Providers", 然后选择"Microsoft.AspNet.Providers"进行安装。
现在我们已经为配置Azure SQL Database做好了准备。我们需要拿到Windows Azure SQL Database的连接字符串。要拿到这个连接字符串,请完成下面的步骤:
3. 登陆Windows Azure管理平台,点击你的SQL Database实例,进入Dashboard界面。在页面的右边,点击"Show Connection Strings"。参考下图:
把ADO.NET的Connection String拷贝到记事本里。
4. 现在回到Visual Studio中,打开项目中Web.config -> Web.Release.config文件。在<Configuration>元素中,添加你的ConnectionString.
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<connectionStrings>
<add name="AzureDB"
connectionString="Server=tcp:h22qoc91jz.database.windows.net,1433;Database=[SopDB];User ID=azureuser@h22qoc91jz;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
请注意,上面只是一个例子,并不是Web.Release.config文件的全部内容。另外,你需要将ConnectionStrings中的{your_password_here}替换成真正的密码。
之后,再按照上一篇文章中的方法发布你的应用即可。
参考:
- Migrating an on-premise database from SQL Server to SQL Azure using SSIS