桌面应用程序无法连接到数据库,但Web应用程序可以

时间:2012-10-19 19:49:21

标签: c# database desktop-application sql-server-2012

我编写了一个C#desktop(winforms)应用程序,它本质上是我编写的Web应用程序的克隆。 Web应用程序可以很好地与数据库进行来回通信。但是,当我安装桌面应用程序时,我收到以下错误:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误

我在桌面应用程序中使用完全相同的连接字符串,就像我在Web应用程序中使用的那样:

"Data Source=tcp:s08.winhost.com;Initial Catalog=THEDATABASE;
            User ID=USERNAME;Password=******;Integrated Security=False;"

我无法使用SQL Server配置管理器,因为我的数据库托管在Winhost.com上。但是他们已经清楚地告诉我,正确的端口是打开的,命名管道是打开的,SQL浏览器配置正确。如果有人遇到过类似问题,请告诉我您为解决此问题所做的工作。我还在下面列出了整个错误。

由于

************** Exception Text **************
System.Data.SqlClient.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. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - 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.) ---> System.ComponentModel.Win32Exception (0x80004005): 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

2 个答案:

答案 0 :(得分:1)

删除TCP协议名称和端口号,然后尝试使用完整的托管网站地址..像这样的东西

  Data Source=www.winhost.com;Initial Catalog=THEDATABASE;
             User ID=USERNAME;Password=**;Integrated Security=False;

答案 1 :(得分:0)

最终我发现问题是代理服务器。具有代理服务器设置的公司正在使用该应用程序,并且由于此端口1433被阻止。我最终通过创建一个Web服务解决了这个问题。