Question

I have an application that makes many connections to both SQL and Oracle DBs. Oracle connection throws this exception many times. I did a search and found this link

http://www.forumtopics.com/busobj/viewtopic.php?p=925784

It looks like a .net issue in Windows as described below

"[The ORA-12542 TNS address in use error] is caused due to the fact that the free ports in the windows client has been exhausted and it is trying to make use of a port which is in TIME_WAIT state which gives the error TNS-12542: Address already in use."

My questions are:

1> Is it possible in .NET to specify the local port range for making connections, e.g., one range of ports dedicate to SQL server connection, and another range of ports to Oracle.

2> How ports are allocated to connections in .Net? So, Time_Wait ports will not be reallocated.

3> For oracle connections, my local ports are allocated with port numbers starting from very high numbers, e.g., 50000, but with SQL Server connections, my local ports start from 5000. Why is that?

4> How to solve this problem?

Thanks in advance.

Edit: We also experience Timed out exception in the SQLServer connections. I think they are related.

Was it helpful?

Solution

This problem can occur if you have connection pooling turned off, and ephemeral ports are exhausted. Using connection pooling reduces the number of connections required to satisfy the same request throughput, and may resolve the problem.

Local port usage is commonly restricted to particular ranges, even for ephemeral ports, to make it easier to identify traffic and manage firewall rules for example.

Connection pooling is generally in place for database connections as connection is a relatively expensive operation. For this reason it is good to reuse connections.

As to why this is preventing you from connecting, you may want to look at this:

Perhaps MaxUserPorts has been modified to a non-default value? By default there should be 3976 ports available allowing 3976 simultaneous connections to the same remote IPaddress/port combination. (The port only has to be unique if the remote end is the same - the combination remoteIP:port plus localIP:port must be unique).

Alternatively, some components manage their own local port allocation rather than delegating to the OS, so perhaps this is the case with SqlConnection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top