TNS Timeout Error when connecting to SQLPLUS through scripts only


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat TNS Timeout Error when connecting to SQLPLUS through scripts only
# 1  
Old 05-19-2012
TNS Timeout Error when connecting to SQLPLUS through scripts only

Hi,

I am facing a strange issue when connecting to SQLPLUS via a shell scripts.

I am using Linux 2.6.18-274.18.1 and gbash shell.

When I connect to SQLPLUS through scripts then it throws TNS Time Out error ""sometimes"" and connects successfully other times.This is only happening when sqlplus is called within scripts and working fine when called directly from terminal.

Database is on differnent machine and TNS and network connections are perfectly set on both machines.Ping stats are also perfect

for demonstration i have created a test script:
Code:
#!/bin/bash
i=0
ID=userid/password@sid
while [ $i -le 3 ]
do
  echo $i
  sqlplus -s ${ID}<<EOF
  select sysdate from dual;
  exit;
EOF
  i=`expr $i + 1`
done

Output:
Code:
 
0
SYSDATE
---------
19-MAY-12
1
SYSDATE
---------
19-MAY-12
2
ERROR:
ORA-12170: TNS:Connect timeout occurred
 
SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> ::= <username>[/<password>][@<connect_identifier>] | /
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
 
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
3
SYSDATE
---------
19-MAY-12

Entries of sqlnet.log :

***********************************************************************
Code:
Fatal NI connect error 12170.
VERSION INFORMATION:
TNS for Linux: Version 10.2.0.3.0 
TCP/IP NT Protocol Adapter for Linux: Version 10.2.0.3.0
Time: 18-MAY-2012 18:26:25
Tracing not turned on.
Tns error struct:
ns main err code: 12535
TNS-12535: TNS:operation timed out
ns secondary err code: 12560
nt main err code: 505
TNS-00505: Operation timed out
nt secondary err code: 110
nt OS err code: 0
Client address: <unknown>


Strange thing is that it connects sometimes and fails other times.
Please help Smilie

Last edited by Scott; 05-19-2012 at 12:00 PM.. Reason: Code tags
# 2  
Old 05-19-2012
Code

Code:
ID="userid/password@sid"

or
Code:
usr=userid
pswd=password
tns=sid

sqlplus -s ${usr}/${pswd}@${tns}

# or

export ID=userid/password@sid


Last edited by Scott; 05-19-2012 at 12:47 PM.. Reason: Use code tags, please...
# 3  
Old 05-19-2012
Quote:
Originally Posted by monalsinha
ID="userid/password@sid"
or
usr=userid
pswd=password
tns=sid

sqlplus -s ${usr}/${pswd}@${tns}

or
export ID=userid/password@sid
Could you explain how you think this would address the issue? I don't see how it could.
# 4  
Old 05-19-2012
ERROR: ORA-12170: TNS:Connect timeout occurred
Code:
SP2-0306: Invalid option. Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}] where <logon> ::= <username>[/<password>][@<connect_identifier>] | / ERROR: ORA-12162: TNS:net service name is incorrectly specified

my answer is based on the fact that somehow connection parameter gets changed
in the 3 attempts and as it is in loop, so i thought there might be some special character.
I understand there is no explanation to this... but i faced this problem sometime back
and solved by putting double quotes.
This User Gave Thanks to monalsinha For This Post:
# 5  
Old 05-19-2012
Password doesn't contains any special character, though I have tried enclosing userid,password and sid in double quotes but no success.

it is not necessary the code will struck at third iteration only.it gets struck at any point.

Another example :

Code:
0
ERROR:
ORA-12170: TNS:Connect timeout occurred

SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_identifier>] | /
ERROR:
ORA-12162: TNS:net service name is incorrectly specified

SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
1
SYSDATE
---------
19-MAY-12
2
ERROR:
ORA-12170: TNS:Connect timeout occurred

SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_identifier>] | /
ERROR:
ORA-12162: TNS:net service name is incorrectly specified

SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
3
SYSDATE
---------
19-MAY-12

# 6  
Old 05-19-2012
it may sound weird but can u try this
Code:
sqlplus -s "${ID}" <<EOF
 select sysdate from dual;
 exit;
EOF

# 7  
Old 05-20-2012
HI Monalsinha, i have tried all the possible combinations but no success.
I think this is not due to any issue in script as the same is happening with other scripts toooo.
Can this be result of any security or network settings of shell?

selinux is disabled on both machines.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sqlplus not connecting the 2nd time in for loop

Hi, I am trying to get the rows(First step is to get the poolid's and then second step run a loop to get the output based on each pool id and third connection is to get the member id and pool id based on a different condition) where based of certain conditions and storing it in a file. I wrote the... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

2. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies

3. UNIX for Advanced & Expert Users

Connecting once using sqlplus and doing multiple queries

Hello everyone, It's my first week using unix and shell scripting. I tried creating a script that has a function that execute SQL query. my script looks something like this: ---------------------------------------------------- #!/bin/sh tableName="myTable" secondTable="secondTable"... (2 Replies)
Discussion started by: edlin_r
2 Replies

4. UNIX for Advanced & Expert Users

TNS no listener error when connecting to a new DB

Hi all We connect to 10 Oracle Databases from our UNIX box through the regular TNS file we have on any oracle client installation. Recently we acquired a new connection. I added the entries as usual to the TNS file. The connection fails with the below error message ORA-12541: TNS:no... (2 Replies)
Discussion started by: b_sri
2 Replies

5. Shell Programming and Scripting

Connecting to Oracle DB using sqlplus

Hi, I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following: 1. Connect to oracle database hosted on a different server 2. fire a query on the oracle db 3. store the output in a variable 4. use this variable for further logic... (26 Replies)
Discussion started by: shrutihardas
26 Replies

6. UNIX for Dummies Questions & Answers

Connecting to Oracle DB using sqlplus

Hi, I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following: 1. Connect to oracle database hosted on a different server 2. fire a query on the oracle db 3. store the output in a variable 4. use this variable for further logic... (1 Reply)
Discussion started by: shrutihardas
1 Replies

7. Shell Programming and Scripting

connecting through sqlplus

I am trying to connect to one of the oracle sever using uni through sqlplus command: sqlplus -s BOXI_ALPH_AUDITOR,Q078_audit$@Q047 But its not getting connected. I tried using some different server using same syntax its working. What differene i found is the password is having no special... (2 Replies)
Discussion started by: gander_ss
2 Replies

8. Shell Programming and Scripting

control timeout of sqlplus process

Hi, I'm using simple sqlplus to test DB availability. When DB is going down, sqlplus command is hang for a few minutes I want to implement the following: 1. execute sqlplus 2. if after 20 sec I dont get a response, kill the process and exit with error. 3. if I get immediate response... (2 Replies)
Discussion started by: gdan2000
2 Replies

9. Shell Programming and Scripting

Showing errors when connecting to sqlplus in shell script

hi, I am trying to automate the compilation of procedures stored in .sql files in Unix. Is there any way in which we can sho err if there errors are raised in the compilation? I am using the following code to connect to the sqlplus sqlplus ${SQL_USER}/${SQL_PASSWORD} (5 Replies)
Discussion started by: silas.john
5 Replies

10. UNIX for Dummies Questions & Answers

error connecting to sqlplus

Hi, I wrote a shell script to call oracle procedure. But when i am trying to connet sqlplus with the fallowing statement It is giving me error " callproce.sh : sqlplus: not found". What could be the problem. sqlplus -s $CONNECT_STRING >$LOGFILE <<!! thank u all papachi (2 Replies)
Discussion started by: papachi
2 Replies
Login or Register to Ask a Question