How come sqlplus not connecting?
Asked Answered
C

9

7

My goal is to connect to an Oracle 9i instance from my OS X machine. I've followed the setup instructions here and got through them with no errors (eventually). However, I'm finding that sqlplus is unable to connect:

[ ethan@gir ~ ]$ sqlplus xxx/yyy@zzz

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Apr 17 10:13:08 2009

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Looooong wait...

ERROR:
ORA-12170: TNS:Connect timeout occurred

Enter user-name: xxx
Enter password: 
ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:

My tnsnames.ora file...

zzz =
  (DESCRIPTION = 
    (ADDRESS_LIST =
      (ADDRESS =
        (PROTOCOL = TCP)
        (HOST = dbhost)
        (PORT = 1521))
    )
  (CONNECT_DATA =
    (SERVICE_NAME = zzz)
  )
)

Maybe there's an env variable that needs to be set?


UPDATE

Able to ping DB host machine no problem.

Tried...

sqlplus xxx/yyy@//dbhost/zzz

Got...

ERROR:
ORA-12170: TNS:Connect timeout occurred

Tried using SID instead of SERVICE_NAME in tnsnames.ora. Did not seem to change the result. Reverted back to SERVICE_NAME.


Last couple entries in sqlnet.log...

***********************************************************************
Fatal NI connect error 12170.

  VERSION INFORMATION:
    TNS for MacOS X Server: Version 10.2.0.4.0 - Production
    TCP/IP NT Protocol Adapter for MacOS X Server: Version 10.2.0.4.0 - Production
  Time: 17-APR-2009 10:33:06
  Tracing not turned on.
  Tns error struct:
    ns main err code: 12535
    TNS-12535: Message 12535 not found; No message file for product=network, facility=TNS
    ns secondary err code: 12560
    nt main err code: 505
    TNS-00505: Message 505 not found; No message file for product=network, facility=TNS
    nt secondary err code: 60
    nt OS err code: 0


***********************************************************************
Fatal NI connect error 12170.

  VERSION INFORMATION:
    TNS for MacOS X Server: Version 10.2.0.4.0 - Production
    TCP/IP NT Protocol Adapter for MacOS X Server: Version 10.2.0.4.0 - Production
  Time: 17-APR-2009 11:24:08
  Tracing not turned on.
  Tns error struct:
    ns main err code: 12535
    TNS-12535: Message 12535 not found; No message file for product=network, facility=TNS
    ns secondary err code: 12560
    nt main err code: 505
    TNS-00505: Message 505 not found; No message file for product=network, facility=TNS
    nt secondary err code: 60
    nt OS err code: 0

PARTIAL ANSWER

Thanks everyone for your answers. They were helpful. I found that there was a DNS issue. I was able to ping by hostname, so thought that should work fine. I also tried I.P. address. Turned out that I needed the internal "10.1.x.x" I.P. address for it to work on this OS X machine (but hostname is fine on Windows).

At this point, I can connect with...

sqlplus xxx/yyy@//INTERNAL_IP/zzz

However, with those values entered into tnsnames.ora, this still doesn't work...

sqlplus xxx/yyy@zzz

...

ORA-12154: TNS:could not resolve the connect identifier specified

I searched for a sample tnsnames.ora file that was close to what I needed and copied the contents into my file. Changed the params and now everything works. Not sure why mine wasn't working.

Captainship answered 17/4, 2009 at 17:33 Comment(0)
T
9

Since you are using a 10g client, it's advisable to use Easy Connect syntax instead:

export TWO_TASK=//dbhost/zzz
sqlplus xxx/yyy

, or just this:

sqlplus 'xxx/yyy@//dnhost/zzz'

Also check your ORACLE_HOME points to the right folder: tnsnames.ora is searched for in $ORACLE_HOME/network/admin/tnsnames.ora

Tempera answered 17/4, 2009 at 17:40 Comment(1)
I think it must be locating the tnsnames file fine, since it is not complaining that zzz is an unknown service.Jostle
A
4

Your brackets seem correct.

Try using the SID:

The following is an example of a tnsnames.ora file:

IDENTIFIER =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP) (HOST = userid.myhosteddb.net)(PORT = 1521))
    )
    (CONNECT_DATA = (SID = odb))
  )

Read about SID here.

Angle answered 17/4, 2009 at 17:45 Comment(0)
U
2

You can use

sqlplus user/password@servicename_host

if you cannot connect you can use

sqlplus user/password@(DESCRIPTION=((ADDRESS=(PROTOCOL = TCP)(HOST = dbhost)(PORT = 1521))(CONNECT_DATA=(SERVICE_NAME = zzz)))

if you are using linux another *Nix OS you need to use quotes else the () are interpreted by the shell

e.g

sqlplus user/password@'(DESCRIPTION=((ADDRESS=(PROTOCOL = TCP)(HOST = dbhost)(PORT = 1521))(CONNECT_DATA=(SERVICE_NAME = zzz)))'
Uncanonical answered 25/3, 2010 at 9:41 Comment(0)
J
1

There is probably a sqlnet.log file being generated in your working directory. This may help you or if you post its contents it might give us more information.

In your example, you're trying two different things. On the command line you used "xxx/yyy@zzz". It looks like this is finding the "zzz" entry in tnsnames.ora successfully, but the timeout indicates that it is getting no response whatsoever from the server. Can you ping dbhost successfully?

On your second try you just entered "xxx" for the username; which makes sense if you are no accustomed to SQLPlus, but as you can see there is no point where it prompts you for the database name. So in this case it was trying to connect to "xxx/yyy" without a service name, leading to the second error. This just means you don't have a default service name set up. So this error comes from incomplete input. (You would enter "xxx@zzz" for the username to specify the service name at this prompt. You can actually enter the whole connect string "xxx/yyy@zzz" at the username prompt, if you don't mind the password being visible.)

Jostle answered 17/4, 2009 at 18:12 Comment(1)
Yes, I can ping the DB host specified in my tnsnames.ora file.Captainship
D
1

Have you tried using telnet to get to the open port to make sure a firewall isn't blocking you? may be worth a try telnet port-num host

Diplomat answered 17/4, 2009 at 18:39 Comment(2)
I'm able to connect to that DB from other machines using tools such as SQLDeveloper, so I know the host allows connections.Captainship
But is a local firewall blocking outbound connections?Diplomat
N
1

Did you set up your environment with the oraenv script?

Have you tried tnsping?

$ tnsping $ORACLE_SID

Perhaps it will help to compare the output on a machine that does connect to the output on a machine that fails to connect. At least that's what I do just before contacting our DBA.

You can get a bit more detail on what the error with the oerr command:

$ oerr ora 12170
12170, 00000, "TNS:Connect timeout occurred"
// *Cause:  The server shut down because connection establishment or
// communication with a client failed to complete within the allotted time
// interval. This may be a result of network or system delays; or this may
// indicate that a malicious client is trying to cause a Denial of Service
// attack on the server.
// *Action: If the error occurred because of a slow network or system,
// reconfigure one or all of the parameters SQLNET.INBOUND_CONNECT_TIMEOUT,
// SQLNET.SEND_TIMEOUT, SQLNET.RECV_TIMEOUT in sqlnet.ora to larger values.
// If a malicious client is suspected, use the address in sqlnet.log to
// identify the source and restrict access. Note that logged addresses may
// not be reliable as they can be forged (e.g. in TCP/IP).
Neckcloth answered 17/4, 2009 at 22:36 Comment(3)
The tools I have available are whatever came with Oracle Instant Client for OS X. That includes sqlplus, but I don't seem to have a "tnsping" command.Captainship
What is the $ORACLE_SID var? That's not in my environment. Does it need to be?Captainship
I don't have any experience with the Oracle Instant Client. I'm pretty sure $ORACLE_SID needs to be set to use the oraenv setup script. Seems like you're missing some pieces there.Neckcloth
G
1

I had a similar problem and it seems that Oracle sqlplus was the problem!

Connecting like either of these works:

   > sqlplus MyUsername/MyPassword@MyHostname:1521/MyServiceName
   > sqlplus MyUsername/MyPassword@//MyHostname:1521/MyServiceName

(the // is optional before the hostname). However, leaving off password or both user/pass fails like this:

    sqlplus @//MyHostname:1521/MyServiceName

    SQL*Plus: Release 11.2.0.4.0 Production on Thu Apr 2 15:59:49 2015

    Copyright (c) 1982, 2013, Oracle.  All rights reserved.

    SP2-0310: unable to open file "//MyHostname:1521/MyServiceName.sql"
    Enter user-name: MyUsername
    Enter password: MyPassword
    ERROR: 
    ORA-12162: TNS:net service name is incorrectly specified

So, even though sqlplus asks you for the username/password, it will stupidly fail with a bogus error message if you type them in at the prompt. It only works if you place them (both!) at the beginning of the connection string.

Stupid Oracle!!!

Grotius answered 2/4, 2015 at 23:8 Comment(0)
F
0

FOLLOW THIS LINK FOR STEP BY STEP INSTALLATION AND POST INSTALLATION METHODS.. BE CAREFULL WITH IT.

And to connect with sql plus:

  1. USERNAME WiLL BE system AS PER THE INSTRUCTION GIVEN IN ABOVE LINK
  2. your password MUST NOT BE tiger but the one which you set at the beginning of the installation

P.S: dont panic if you find problem (browser incompatibility) connecting Oracle Enterprise Manager while testing installation if your browser is Google Chrome. hit the back page arrow and next page arrow to agree terms and clicking ok.

I resolved this problem on my machine in a day.. but it will be a matter of couple of hors for you.

soruces: i am computer science engineer mostly code in java

Fluoride answered 10/9, 2013 at 9:34 Comment(0)
L
0

I had the same error (ORA-12162: TNS:net service name is incorrectly specified) but a different reason (On Windows 7 Enterprise 64-bit). Hope this helps someone:

I.T. at my work installed 32bit and 64bit Oracle, and based on my PATH variable, the shell looked in the 64-bit path for SQLPLUS.exe compared to the 32-bit path.

The different paths use different TNSNAMES.ora files and I didn't have my connection string in the 64-bit path:

Oracle\product\11.1.0\client_1_64bit\network\admin\TNSNAMES.ora

I only had the connection string in the 32-bit TNSNAMES.ora: Oracle\product\11.1.0\client_1_32bit\network\admin\TNSNAMES.ora

Also, since there were multiple ORACLE installations I had to remove the ORACLE_HOME environment variable so that both installs can use different home directories.

Leslielesly answered 21/10, 2013 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.