Connection.open for hangs indefinitely, no exception is thrown

前端 未结 2 971
庸人自扰
庸人自扰 2021-01-04 04:06

When I try to do the following code, the program hangs indefinitely. I don\'t know why and there seems to be other unanswered topics on the matter. Although, if the IP\\webs

2条回答
  •  执笔经年
    2021-01-04 04:27

    If you have set an FQDN (Fully Qualified Domain Name) for your Data Source such as example.com and the DNS server is unable to resolve this FQDN for a long time it is pretty obvious that your request will hang out. Make sure that the machine from which you are running your application can reach the SQL server and resolve it without any issues. Also you probably want to make sure that there is no firewall that might be blocking the request.

    Another possible cause for those symptoms is if you have exhausted the connection pool of ADO.NET. This could happen if you have many slow SQL queries running in parallel, each of them taking a physical connection to the database. There is a limit in the number of available connections on this pool and when this limit is reached the next call to connection.Open() might wait for an available connection to be returned to the pool.

    Remark: you might also need to specify in your connection string how you want to authenticate against the SQL server. Checkout connectionstrings.com for more examples.

    All this is to say that there is absolutely nothing wrong in the C# code you have posted in your question. It looks more like a network related problem that you could bring to the attention of your network administrators.

提交回复
热议问题