Solved

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

Posted on 2010-11-30
6
4,755 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
6 Comments
 
LVL 76

Expert Comment

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

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

Expert Comment

by:johnsone
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 150 total points
Comment Utility
0
 
LVL 5

Accepted Solution

by:
anand_20703 earned 350 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now