0

I am running SQLcl verion

SQL> version
Oracle SQLDeveloper Command-Line (SQLcl) version: 19.1.0.0

The following script works

echo @test/oracle_sql_cl/read_schema.sql | sql -S ${USER}/${PASSWORD}@${TNS_NAME}

A timeout parameter is needed.

Here are some examples tired but without success

echo @test/oracle_sql_cl/read_schema.sql | sql -S -t 5 ${USER}/${PASSWORD}@${TNS_NAME}

The above command fails.

Also updated the TNS_NAME var like so

export TNS_NAME="(DESCRIPTION=(TRANSPORT_CONNECT_TIMEOUT=5)(CONNECT_TIMEOUT=5)(RETRY_COUNT=1)(RETRY_DELAY=1)(ADDRESS_LIST=(ADDRESS=...

But connection still reties the connecion.

Any ideas would be much appreciated :~)

Solution

Update the connection string to include

export TNS_NAME="(DESCRIPTION=(TRANSPORT_CONNECT_TIMEOUT=2)...

And modify the invocation to

echo @test/oracle_sql_cl/read_schema.sql | sql -S ${USER}/${PASSWORD}@${TNS_NAME}
2
  • 1
    "The above command fails." This is not a constructive statement as we cannot see the failing command (it's a call to a script and you do not include the script) and you do not tell us HOW it fails. If the script takes 10 minutes to run and you've told it to time-out after 5 minutes then of course it is going to timeout. Please edit the question and include a minimal reproducible example with a complete description of the problem including the failing script and the complete error messages.
    – MT0
    Commented Jun 22, 2023 at 12:47
  • On a side note, it is considered extremely bad security practice to place user credentials into environment variables such as you are doing in your example. When the process is executed, the value of the variable is placed into the command line and is then visible to literally any user on the system using the ps command.
    – pmdba
    Commented Jun 22, 2023 at 13:07

1 Answer 1

1

Use a JDBC URL in your connect string.

With timeout set to 10 milliseconds it fails.

With timeout set to 1000 milliseconds it works.

SQL> connect system/oracle@jdbc:oracle:thin:@(DESCRIPTION=(TRANSPORT_CONNECT_TIMEOUT=10ms)(ADDRESS_LIST=(ADDRESS=(HOST=server.com)(PORT=2213)(PROTOCOL=tcp)))(CONNECT_DATA=(S
ERVICE_NAME=DB213P)))
  USER          = system
  URL           = jdbc:oracle:thin:@(DESCRIPTION=(TRANSPORT_CONNECT_TIMEOUT=10ms)(ADDRESS_LIST=(ADDRESS=(HOST=server.com)(PORT=2213)(PROTOCOL=tcp)))(CONNECT_DATA=(SERVICE_NAME=DB213P)))
  Error Message = IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=MES6gto9SkeXW93/WnHZ6A==)

SQL> connect system/oracle@jdbc:oracle:thin:@(DESCRIPTION=(TRANSPORT_CONNECT_TIMEOUT=1000ms)(ADDRESS_LIST=(ADDRESS=(HOST=server.com)(PORT=2213)(PROTOCOL=tcp)))(CONNECT_DATA=
(SERVICE_NAME=DB213P)))
Connected.
SQL>

This JDBC property CONNECTION_PROPERTY_THIN_NET_CONNECT_TIMEOUT is defined/documented here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.