c# - Connection.open for hangs indefinitely, no exception is thrown -


when try following code, program hangs indefinitely. don't know why , there seems other unanswered topics on matter. although, if ip\website cannot reached, works intended.

    private void dostuff()     {         string connectionstring = "data source=www.google.com;connection timeout=5";         using (sqlconnection connection = new sqlconnection(connectionstring))         {             connection.open(); //hangs here indefinitely             console.writeline("test");         }     } 

for example, if set connection string

connectionstring = "data source=www.nonexistentsite.com;connection timeout=5";

then throw exception. how throw exception active site? ... google testing purposes, obviously.

edit :

if try connect unreachable server name or ip address will exception...

a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: named pipes provider, error: 40 - not open connection sql server)

update :

after letting program run quite while, times out after 3-5 minutes , gives me error posted above. how can timeout quicker?

if have set fqdn (fully qualified domain name) data source such example.com , dns server unable resolve fqdn long time pretty obvious request hang out. make sure machine running application can reach sql server , resolve without issues. want make sure there no firewall might blocking request.

another possible cause symptoms if have exhausted connection pool of ado.net. happen if have many slow sql queries running in parallel, each of them taking physical connection database. there limit in number of available connections on pool , when limit reached next call connection.open() might wait available connection returned pool.

remark: might need specify in connection string how want authenticate against sql server. checkout connectionstrings.com more examples.

all there absolutely nothing wrong in c# code have posted in question. looks more network related problem bring attention of network administrators.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -