【发布时间】:2012-10-19 19:49:20
【问题描述】:
我编写了一个 C# 桌面 (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
【问题讨论】:
-
Web 应用程序在同一台机器上吗?你检查过防火墙是否关闭了吗?
-
这可能是一个愚蠢的问题,但是您是否允许该应用程序通过您的防火墙?
-
异常中可能隐藏了更多信息,可以告诉您更多关于正在发生的事情。深入研究
InnerException属性(并记住嵌套异常本身可能有嵌套异常)。此外,请检查Data属性以获取任何其他信息 - ADO.NET 特别擅长将有用的详细信息放入该字典中。 -
holeydood3,是的,我关闭了防火墙。这里还有一些奇怪的东西。桌面应用程序在我的家用电脑(我开发的电脑和我妻子的电脑)上运行良好,但在我家之外根本无法运行。奇怪的是,我的连接字符串中没有对任何本地数据库的任何引用。希望这会有所帮助。
-
是的,Web 应用程序在同一台机器上。我确实尝试关闭了我的防火墙,但它仍然无法正常工作。
标签: c# database desktop-application sql-server-2012