oracle / dotnet-db-samples

.NET code samples for Oracle database developers #OracleDotNet
http://otn.oracle.com/dotnet
MIT License
413 stars 191 forks source link

Oracle.ManagedDataAccess.Core - Retry Count not working #331

Closed dmitriy-shleht closed 10 months ago

dmitriy-shleht commented 10 months ago

Oracle.ManagedDataAccess.Core v3.21.120

We have two database servers, and we need to connect to the second server if the first server fails.

Here is our connection string:

User Id=TEST;CONNECTION TIMEOUT=10;HA Events=true;Data Source=(DESCRIPTION =
 (TRANSPORT_CONNECT_TIMEOUT=10) (RETRY_COUNT=1)(RETRY_DELAY=5)
 (ADDRESS_LIST =
(LOAD_BALANCE=on)
( ADDRESS = (PROTOCOL = TCP)(HOST=172.30.2.211)(PORT=1521)))
 (ADDRESS_LIST =
(LOAD_BALANCE=on)
( ADDRESS = (PROTOCOL = TCP)(HOST=172.30.2.212)(PORT=1521)))
 (CONNECT_DATA=(SERVICE_NAME = odb)))

The RETRY_COUNT parameter is not working as expected. When we try to open the connection initially, we get a Connection request timed out exception, and when we try to open the connection again, we successfully connect to the database server. How can we make it so that it connects to the second server (172.30.2.212) immediately without throwing an exception?

alexkeh commented 10 months ago

Your TRANSPORT_CONNECT_TIMEOUT is the same value as your CONNECTION TIMEOUT. When the connection attempt to 211 fails, so does ODP.NET's overall attempt to connect.

Increase your ODP.NET connection timeout and/or decrease your TRANSPORT_CONNECT_TIMEOUT. The latter can be specified in milliseconds so that you can try the second server very quickly if the first server can't deliver a connection quickly.

dmitriy-shleht commented 10 months ago

Yes it worked, thank you very much. Another question, the LOAD_BALANCE=on parameter - does something affect?

alexkeh commented 10 months ago

LOAD_BALANCE enables load balancing between addresses at connection time.