I have a SQL query and it fails at times. That means that query runs fine most of the times. Once the query fails if I execute is again with some delay, it is successful in the same execution.
Please note there are no changes in the tables being used in the query in between the success and failure scenarios. They are exactly same. As mentioned below, the query joins couple of tables and the result of the query should be empty. But at times ADO throws and error.
How one goes about finding out the root cause of the problem?
I left out some of the details intentionally, since I am interested in knowing generic problem solving approach for SQL query failures.
Here are some details to know about any specific alternative approaches as well.
- Microsoft SQL Server 2008
- Query use joins two tables
- Query is passed from .NET through interop and a COM component deals with ADO to execute the query.
- Error info 0x80004005(-2147467259) [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Update:
For this specific problem, I figured that the client runs out of available TCP ports. As per default settings 5000 ports are the max number of TCP ports. In my case, ADO creates implicit connections, which create TCP port every time a query is made.
netstat
showed me that the number of ports open dramatically increased when I ran the workflow. At around 4000 ports the query fails (0-1023 are reserved ports). Answer from Jibcov Dobrev in here pointed me to the right direction.