我只是将我的项目上传到Windows Azure网站 free version .
我的网站需要连接到另一个Web托管上的外部SQL服务器 . (不是Windows Azure上的SQL服务器) .
当我在我的电脑上开发时 . 一切都很好(这意味着我的连接字符串是正确的) .
但是当我上传到windows azure时 . 它无法连接到该数据库 .
并抛出这样的异常 .
Access is denied
当我做以下这个答案,错误显示像这样Connecting to remote SQL Server 2008 from Windows Azure
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
并且都显示像这样的堆栈跟踪
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
我该如何解决这个问题,请帮忙 .
3 回答
您正在将应用程序上载到Windows Azure网站 . 最可能的端口1433连接到SQL Server在其防火墙上默认被阻止 . 由于您使用的是azure网站,因此无法控制此防火墙设置 .
你可以:
将现有SQL Server数据库迁移到SQL Azure并从那里使用它
将您的应用程序升级到Cloud Service,您可以在其中定义连接到外部数据库所需的 endpoints (我不建议这样做,因为部署时会非常慢)
找到一种方法将现有数据库发布为Web服务,以便您可以从应用程序中使用它们,但您可能需要重写应用程序的数据访问层 .
我只是将所有内容移到SQL Azure,它非常简单 .
如果您可以将网站添加到托管数据库的远程主机,您是否可以在允许您与数据库通信的同一主机上创建服务(例如WCF或Rest)?这样,您仍然可以在外部主机上托管数据库,并通过Azure网站上的服务与其进行通信 .
看起来有一种新方法允许Azure Web应用程序使用混合连接连接到本地SQL Server . 谷歌让我相信这个功能在2016年的某个时候可用 . 它需要你在托管你的SQL Server实例的机器上安装其他软件 .
More information available here.