Solved

how to set a connection timeout for ORACLE PLSQL UTL_TCP.open_connection

Posted on 2010-11-30
6
5,575 Views
Last Modified: 2012-06-27
anybody know how to set a connection timeout?  if the host is down the open_connection takes 3 or 4 minutes of hanging and then an exception.  A host being down can happen and it would be good to set say a 10 second timeout.

TNS:operation timed out
ORA-29260: network error: TNS:operation timed out

DECLARE
  c  utl_tcp.connection;  -- TCP/IP connection to the Web server
  ret_val pls_integer;
BEGIN
  c := utl_tcp.open_connection(remote_host => '8.8.8.8',
                               remote_port =>  9330,
                               charset     => 'US7ASCII');  -- open connection
  ret_val := utl_tcp.write_line(c, 'GET /axis/services/NSRAPIService HTTP/1.0');    -- send HTTP request
  ret_val := utl_tcp.write_line(c);
  BEGIN
    LOOP
      dbms_output.put_line(utl_tcp.get_line(c, TRUE));  -- read result
    END LOOP;
  EXCEPTION
    WHEN utl_tcp.end_of_input THEN
      NULL; -- end of input
  END;
  utl_tcp.close_connection(c);
END;
0
Comment
Question by:cavtel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34242223
There appears to be a timeout parameter for open_connection:

http://psoug.org/reference/utl_tcp.html
0
 
LVL 35

Expert Comment

by:johnsone
ID: 34242382
From the doc:

http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/u_tcp.htm#i997069

You should be able to supply the TX_TIMEOUT parameter to the OPEN_CONNECTION function.
0
 

Author Comment

by:cavtel
ID: 34249051
unfortunately that tx_timeout is transfer_timeout used for read and write, after the connection is made.

the utl_http function works the same way, you can set a request timeout, but not on the initial connection.

the connection will hang for 3 minutes, i was trying to figure out an alter session parameter to shorten that 3 minutes as a work around.  but couldnt figure that out either.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34250542
UTL_TCP might be governed by the sqlnet parameters.  You might tweak these to see if they make a difference:

http://download.oracle.com/docs/cd/E11882_01/network.112/e10835/tnsnames.htm#NETRF1434
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 150 total points
ID: 34250558
0
 
LVL 5

Accepted Solution

by:
anand_20703 earned 350 total points
ID: 34291363
in database server's listener.ora, there are two parameters.
inbound_connection_timeout parameter, and outbout_connection_timeout parameters.
For example, if the value is 60 and the connection is not made successful within 60 seconds, then timeout happens. With your requirement, you can try these values by setting 10.i.e, 10 seconds.
For exact parameter name, u can google. Listener restart is required when a change happens in listener.ora to take effect.
1

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question