gpt4 book ai didi

c# - SqlConnection.Open() 在 Windows XP 上挂起

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:39 24 4
gpt4 key购买 nike

我在 .NET 控制台应用程序中有一段简单的代码,它试图打开与服务器的 SQL 连接:

using (SqlConnection connection = new SqlConnection("<my connection string>"))
{
connection.Open();
}

它在我的 Windows 7 机器上运行良好,但在我的另一台运行 Windows XP x64 的机器上,对 Open() 的调用无限期挂起。

知道为什么会发生这种情况,或者我如何诊断原因?我在两台计算机上都从管理员帐户运行该程序。

编辑:好的,这似乎是防火墙问题。我已将我的 Windows 7 机器连接到与 Windows XP 机器相同的互联网连接,现在它也挂起...我需要打开哪些端 Eloquent 能让 SQL 流量通过,我该如何打开它们?

编辑:以防万一有人感兴趣,我的网络管理员出于对 Slammer 蠕虫的恐惧而阻止了到端口 1433 的传出流量......

最佳答案

因为我可以 ping 并尝试连接到 database2.ehost-services.com(虽然我收到登录失败),让我们尝试简化您的连接字符串:

Data Source=database2.ehost-services.com;Initial Catalog=myDatabaseName;User ID=myUser;Password=myP@ssword;

编辑

要回答有关连接字符串为何未超时的问题,MSDN描述连接字符串的pooling属性如下:

When the value of this key is set to true, any newly created connection will be added to the pool when closed by the application. In a next attempt to open the same connection, that connection will be drawn from the pool.

Connections are considered the same if they have the same connection string. Different connections have different connection strings.

The value of this key can be "true", "false", "yes", or "no".

所以我在想,也许您的连接实例实际上还没有被合并到超时。

编辑

从您的错误消息来看,您似乎使用的是 NAMED PIPES 而不是 TCP/IP。也许this可以帮助你(使用 SQL Server 配置管理器来选择你的协议(protocol))。在 [SQL Native Client 9.0/10.0 Configuration] 下检查,您应该会看到一个协议(protocol)列表。确保 TCP/IP 在命名管道之前以顺序列出并且也已启用。例如,我的顺序 1 - 3 是共享内存、TCP/IP、命名管道和禁用 VIA。

编辑

尝试创建一个选择了 TCP/IP 协议(protocol)的别名并连接到您的别名?您也可以使用 SQL Server 配置管理器执行此操作。

编辑

由于OP已经解决了这个问题,我确实对别人的回答发表了评论:

A security policy that blocks outgoing would have to be explicitly created

SOB,就是这样 - 网络管理员阻止了端口 1433 上的传出流量。很高兴你知道了!

关于c# - SqlConnection.Open() 在 Windows XP 上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4893786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com