开发者

SqlConnection.Open() hangs on Windows XP

I have a simple piece of code in a .NET console application that tries to open an SQL connection to a server:

using (SqlConnection connec开发者_如何学Ction = new SqlConnection("<my connection string>"))
{
    connection.Open();
}

It works perfectly fine on my Windows 7 machine, but on my other machine running Windows XP x64 the call to Open() hangs indefinitely.

Any ideas why this is happening or how I can diagnose the cause? I am running the program from an administrator account on both computers.

EDIT: Ok, it seems to be a firewall issue. I've connected my Windows 7 machine to the same internet connection as the Windows XP machine and now it hangs too... what ports do I need to open to let SQL traffic through, and how do I go about opening them?

EDIT: In case anyone's interested, my network admin was blocking outgoing traffic to port 1433 out of fear of the Slammer worm ...


Since I can ping and attempt to connect to database2.ehost-services.com (though I received a Login failed), let's try to simplify your connection string:

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

EDIT

To answer your question regarding why your connection string did not time out, MSDN describes the pooling attribute of the connection string as follows:

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".

So I'm thinking perhaps your connection instance wasn't actually pooled yet to time out.

EDIT

From your error message it looks like you're using NAMED PIPES instead of TCP/IP. Maybe this can help you out (use SQL Server Configuration Manager to select your protocol). Check under [SQL Native Client 9.0/10.0 Configuration] and you should see a list of protocols. Make sure TCP/IP is listed with an order before Named Pipes and is also ENABLED. For example, my order of 1 - 3 is Shared Memory, TCP/IP, Named Pipes, and VIA is disabled.

EDIT

Try creating an Alias with TCP/IP protocal selected and connecting to your alias? You can do this also using SQL Server Configuration Manager.

EDIT

As the OP has resolved the issue, I did make the comment on someone else's answer:

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

and SOB, that's what it was - network admin blocked outgoing traffic on port 1433. Glad you figured it out!


Are you sure your database server is accessible from both of your PCs? Have you tried connecting to it from the problematic system using another tool?

And how long have you let it run?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜