Why can I log in with SQL Developer but not with SQL*Plus? - oracle

I'm trying to connect to from SQL*Plus and get error ORA-12154, but I can connect from SQL Developer without any error. I can tnsping and also lsnrctl is okay and the listener is up and running.
I can connect as sys like sqlplus sys as sysdba which works fine; but with another user I do sqlplus username and when I type the password it gives me:
ORA-12154: TNS:could not resolve the connect identifier specified

SQL*Plus interprets an # symbol as the start of a TNS alias. If your password has that in it then it will be interpreted that way even if you are not trying to connect over SQL*Net, but with a local connection. So if you do:
sqlplus user/p#ssword
... then it will take just the p as the password, and the #ssword as the alias, so it will try to find a TNS alias of ssword in your tnsnames.ora file. Since that doesn't exist, you'll get the "ORA-12154: TNS:could not resolve the connect identifier specified" error.
That applies when you put your password in at the prompt too, so if you do:
sqlplus user
Enter password: p#ssword
you'll get the same thing. You can connect by enclosing the password in double-quotes:
sqlplus user
Enter password: "p#ssword"
but you can't do that with the unprompted version.
You're probably better off changing your password to something without that particular character if you want to be able to connect from SQL*Plus as well as from other clients that don't interpret TNS in the same way.
SQL Developer, for example, accepts the password and connection settings as separate fields; it isn't trying to parse the string you entered to identify its components, so it doesn't get confused. Even if you tell SQL Developer to connect using a TNS alias, it will use the tnsnames.ora value you select from its drop-down list, it won't try to take it from the user or password fields.

This one worked for me ( and was easier to implement from my behalf )
From : TNSPING OK but sqlplus gives ORA-12154?
Create an environment variable TNS_ADMIN that points to the directory where your tnsnames.ora file resides. Then try to connect with sqlplus.
TNS_ADMIN = D:\oracle\12.1.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora
If that works, then my guess is you maybe installed the Oracle client software too, and when you run sqlplus, it looks for the tnsnames.ora file in your client home.
-- Instructions for Adding the Environment variable TNS_ADMIN in windows
Go to control panel / system
select Advanced system settings
Select "Advanced" tab, and the environment variable button is at the bottom.
create new variable TNS_ADMIN and give the path where the .ora files are stored. e.g. C:\app\oracle\product\11.2.0\client_1\network\admin

Related

Can connect to database with sqlplus directly, but not when setting ORACLE_SID

I am trying to connect to a database in a shell script. I can connect fine if I use this:
sqlplus user/pass#db_service_name
However, when I try something like this, it is not working:
ORACLE_SID=db_sid
export ORACLE_SID
sqlplus /nolog
connect user/pass
I get an error:
ERROR:
ORA-12545: Connect failed because target host or object does not exist
Obviously I am missing something, but this is an area I am not fully familiar with, so I am not sure where I am going wrong. My assumption was that if I set the ORACLE_SID, that I would not need to identify my db when connecting in sqlplus. Is my assumption incorrect? Or am I missing some required step or configuration?
Using sqlplus user/pass#db_sid refers to a TNS alias in $ORACLE_HOME/network/admin/tnsnames.ora. If the instance is running on the same host as your sqlplus command, then you need to look at the text of the TNS alias in tnsnames.ora and set ORACLE_SID to the SID referenced in the file and then execute . oraenv. If the instance is not running on the same host as your sqlplus command, then your latter attempt will never work.
If you want more secure connections, you might consider using a wallet.

Not able to login by SSO in oracle database when i set TNS_ADMIN parameter

I have my single sign on activated on oracle database D1 and other oracle database D2 which has password login method. I don't want to use oracle home Tnsnames.ora file. I created my own tnsnames.ora and added the both the databases.
I set TNS_ADMIN as path under which I give path of location where I keep my tnsnames file.
I try to do sqlplus /#db1 in command prompt then it throws an error saying "invalid username /password"
But when I use sqlplus /#db1 before tsetting TNS_ADMIN parameter, it takes my local tns file (I guess) and login properly.
Now after setting TNS_ADMIN, if I try sqlplus user/pass#DB2 this works properly as DB2 is accessed using password and SSO isn't activated on this server.
Issue is SSO login in SQLplus doesn't work when I set my TNS_ADMIN parameter, tns entries are correct as I use the same db1 which was before activating SSO.
Do I need to add some parameter in sqlnet.ora located at my tnsnsames file to activate my SSO or any special setting DBA do to activate SSO on user and tns so that I can also do the same to use my tnsnames.ora file.
Scenario
cmd > sqlplus /#db1 --Logs successfully
cmd> set TNS_ADMIN=path/tns (my tnsnames.ora file location)
cmd > sqlplus /#db1 --Logs successfully --Fails to login
cmd > sqlplus user/pass#DB2 --Logs successfully
Note that my tnsnames.ora is not changed and is kept original with connection use for db1 when it was password login.
We use Kerberos for this SSO login for oracle sqlnet file in oracle home path, we have set some parameters related to Kerberos such as Kerberos_CC_NAME, Kerberos_CONF, Kerberos_CONF_MIT parameters. I used the same in my sqlnet file but it didnt works.
You have to specify location of your wallet in sqlnet.ora file, see Profile Parameters (sqlnet.ora)
In case of problems edit your sqlnet.ora file and add these lines
TNSPING.TRACE_DIRECTORY = path (location where you like to get trace file)
TNSPING.TRACE_LEVEL = user
The trace file should provide more information what is going wrong.

Default username and password for SQL*Plus in Ubuntu 14.04?

I followed the instructions mentioned to install SQL*Plus from Oracle Instant Client and How to Install SQLPlus.
SQL*Plus is successfully installed on my system but I cannot login and use it. There is a similar question here and here, but it is does not solve my problem.
On googling, most sources said that we enter a password upon installation, but I was neither prompted nor displayed any password. (I can attach terminal screen shots if it is required)
Is there any way I can login and start using SQL*Plus? Is there any default username or password?
I am stuck here: sqlplus username/password#//dbhost:1521/SID
I need a valid username and password. scott/tiger was of no help.
sqlplus / as sysdba gives this -> ERROR: ORA-12162: TNS:net service name is incorrectly specified and prompts me to enter username and password which I don't have.
I originally asked this question on AskUbuntu feeling its more appropriate there. If this question does not belong here, please comment and I will remove it.
EDIT:
I executed these statements after reading from here:
ORACLE_HOME=/u01/oracle; export ORACLE_HOME
ORACLE_SID=asdb; export ORACLE_SID
Now, On executing sqlplus / as sysdba I get the error message
ERROR: ORA-12545: Connect failed because target host or object does not exist
On executing sqlplus64 scott/tiger#//dbhost:1521/SID I get the error message
ERROR: ORA-12154: TNS:could not resolve the connect identifier specified
It does not have anything to do with Ubuntu. When you enter sqlplus / as sysdba sqlplus tries to connect to the local database, which sid and oracle home should be specified by the environment variables ORACLE_SID and ORACLE_HOME. You, obviously, have not defined these variables.
All you need is to get the username, password, host name, where your database is located, port for the listener (the default port is 1521) and the Oracle SID. Then connect with sqlplus username/password#//dbhost:1521/SID. If you know the password for SYS user and have orapwSID file in the $ORACLE_HOME/dbs directory on the server side, you can connect with sys with the following command: sqlplus sys/password#//dbhost:1521/SID as sysdba.
moving everything into instant_client_11_* directory worked for me.

How to find Oracle database connection details

I am new to Oracle DB and have created a new Oracle 12c database. I am creating a new connection through SQLDeveloper and where can I get the connection details? HostName? Port? SID?
I tried connecting using default details given in documentation but got the below error
Test failed: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor>
You really need to give more info if you need help :)
What Server are you using? Linux? Windows?
Post your oratab file (/etc/oratab)
Post your TNS file ($ORACLE_HOME/network/admin/tnsnames.ora)
Post your Listener file ($ORACLE_HOME/network/admin/listener.ora)
Assuming you're using Linux :D
You need to look at the file "/etc/oratab" if you're on Linux.
This will contain your SID.
Your TNS (located in $ORACLE_HOME/network/admin/) should contain the TNS Entry with SID as per your oratab file.
This is an example entry you will find in the oratab file:
orcl:/opt/oracle/product/10.2.0/db_1:Y
The let hand side "orcl" is your SID, and you will use this for your SID in the Oracle TNS.
If you find that your TNS is configured correctly, then the error message you provided may also indicate that your Database was not registered to the Listener.
You may connect to the sql database as follows:
Set your Oracle Environment
$ . oraenv
Prompts for SID: Enter the value "orcl" (if this is your SID?)
now login:
$ sqlplus / as sysdba
This will log you into oracle as a sysdba.
Execute the follwing:
SQL> Alter System Register;
You should notice a confirmation message that the system is altered.
now exit SQLplus, and try again
SQL> exit
On Windows ISTR, to get the SID, look at the running processes and you should see something called "oracleXXX.exe" or similar. The XXX will be your SID.
You should also see a "TNS" or "Listener" process, probably with the same "XXX".
To get the port number, (usually 1521-1526), find the folder where Oracle was installed to "the "Oracle Home") and in there go to the "network\admin" folder. You should see a "listener.ora" file in there, and if you view this is notepad you should be able to figure out what the port is set to.
This file should also tell you what host/network address the listener is attaching to - you use this IP as the "Hostname" in you connection. Sometimes (again I'm a bit cloudy with Oracle on Windows) the listener.ora might be named listnereXXX.ora, with XXX matching the value you will have seen in SID the checks above.
Obviously if you are new to Oracle, do not amend these files.
If you have netstat/wireshark or similar you can see what the port is attached to the TNS/Listener process.
If you have installed it on same machine on which you are running sql-developer then
host: 127.0.0.1
port: 1521
username and password same as you put while installing oracle datatabse.
keep sid blank

ORA-12543: TNS:destination host unreachable but telnet and tnsping works

Last days i stay face to face with a strange oracle problem.
I have defined database in tnsnames.ora. Oracle client is installed , client and client/bin have been added to PATH.
Ping works, tnsping works, I can connect to host by database port with telnet.
When I try to run application that tries to connect to db I got
ORA-12543: TNS:destination host unreachable
It is the same situation when I try to connect by sqlplus
sqlplus username/password#TNSNAME
Situation occurred only on one workstation, it's mean in common it should works.
WS is windows 7 64 bit.
Database :
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
I was having the same problem, I resolved it by changing my password and removing "#" character. It worked for me.
# is to tell SQL plus which connection identifier (service name/sid) we want to connect. In short, avoid using this character in password.
I also faced the same issue ORA-12543: TNS:destination host unreachable
i resolved it in this way
open sqlplus
connect
enter user-name :system
enter password : HHHHH#2014
then the following error raised
the problem is my password contains # symbol
resolved it by putting my password in "HHHHHH#2014"
I too got ORA-12543 :TNS :destination host unreachable.
But for me the problem was in the password.
Resolution : Need to remove "#" from the existing password as
# defines connection identifier being used to connect in sqlPlus.
To update the password , follow below steps :
Logon to window cmd then type "sqlplus /nolog"
then "connect / as sysdba" .
Once you are connected, change the SYS password to something without #:
"ALTER USER sys IDENTIFIED BY new_password;"
(log in as sys dba)
sql>conn / as sysdba
(then alter the user)
sql>alter user username identified by newuserName
sql>commit
(now again try to login with new user with the same password it will work)
click on 1 to see the screenshot -- ][1]
Recently, I installed Oracle 11g for testing purpose and after completion of installation Database 11g Express Edition started on the browser with the system and Pravin#01 password it is connected successfully. After I tried using SQL Developer tool it was also working fine but while I tried to connect using SQL PLUS command line tool it suddenly gave me an error as,
ORA-12543: TNS:destination host unreachable
Then after research for an hour, I got a solution that Oracle treats # character in the password as a `
service name or sid
so the solution for this problem is to remove # character from the password using
ALTER USER system IDENTIFIED BY ' here is your new password which should contain character
and digits only try to eliminate special characters';
I think this post may be helpful for you.
I have tested this in Windows 2016 environment with Oracle 18c 64-bit
Use this following escape character sequence when attempting to logon with an "#" in the password.
user: scott
password: scott#test
sqlplus scott/\”scott#test\”#TEST_DB
In order avoid this annoyance, change password without an # character using the following command once you have logged in to sqlplus.
alter user scott identified by "newpassword"
Use URL Encoding for special characters in your password instead of raw special characters while connecting through terminal.
Example :-
if your connection string is :- sqlplus system/Password#12345#oracle as sysdba;
Then
Acceptable connection url will be :- sqlplus system/Password%4012345#oracle as sysdba;. Here %40 is the URL Encoding for #, so replace all special characters with their respective URL Encoding and execute the connection command in terminal.

Resources