2015-02-11 110 views
1

我已经构建了一个.asmx Web服务,它从本地sql server 2014数据库中检索信息。 一切工作在本地主机上正常,但将Web服务发布到Azure中后,我得到的错误:Web服务 - SQL连接字符串

An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll

Additional information: Server was unable to process request. ---> A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

SQL Server配置为允许远程连接。

我的连接字符串是这样的:

string con2 = @"Data Source=OfficePc\MSSQLSERVER2014;Initial Catalog=Database;Persist Security Info=True;User ID=Admin;Password=123456"; 

是错误的东西从连接字符串中缺少的结果,还是我失去了一些配置的变化?

+0

您确定这是正确的连接字符串吗?例如,如果您使用Visual Studio,则可以在“服务器资源管理器”窗口上进行检查。 – 2015-02-11 11:42:00

+1

基于Azure的Web服务知道'OfficePc \ MSSQLSERVER2014'在哪里?这不应该是一个IP或什么? – 2015-02-11 11:44:51

回答

1

正如保罗在这个问题下的评论中提到,你的连接字符串指向本地数据库资源(可能在您的开发机器上)。即使您将本地数据库服务器配置为支持远程连接,地址OfficePc\MSSQLSERVER2014也不可寻址,因为这不等同于机器地址(IP地址)。

您的应用程序需要通过访问的IP地址(这可能需要你做你的本地网络上的某些端口转发,或在防火墙上打开的端口)连接到你的数据库。

或者,您可以天青(或者与在虚拟机中的SQL Server或SQL数据库服务)迁移数据库。

请记住:如果您正在访问来自Azure的本地(本地)数据库服务器,会有延迟增加,以及一些出口带宽的成本。

0

它看起来像SQL Server实例没有运行或无法访问。尝试使用SSMS连接到同一个数据库,并且如果得到相同的错误,那么该实例没有运行。

+0

连接字符串尝试引用本地数据库服务器,而Azure中不存在该服务器。 – 2015-02-11 13:15:49

0

大多数情况下,当数据库服务器未找到时发生错误。重新检查是否正确提及服务器名称(数据源)。如果手动生成连接字符串,则使用.uld文件生成连接字符串。

要自动生成使用.UDL文件的连接字符串:

  1. Create a sampe.txt file.
  2. Rename it as sample.udl file.
  3. Then double click on it, It will show you window entitled 'Data Link Properties'.
  4. Configure the connection there.
  5. Then Test the connection using test connection button.
  6. Then open the file with notepad. It will show you the exact connection string.

enter image description here

更多参考检查:MSDN