Unable to connect to oracle with different OS user accout - oracle

I have installed Oracle on Ubuntu with OS user oracle. When I try to connect to Oracle when logged on as different OS user (other than oracle), I get error:
SQL> connect user1/user1#orcl
ORA-12154: TNS:could not resolve the connect identifier specified
However, if I don't mention Oracle SID then I don't get any error:
SQL> connect user1/user1
Connected to:
Oracle Database
SQL>
I have declared ORACLE_HOME and SID in the user profile. But it did not work. Can someone please help me to understand the issue.

In a sense you don't really have a problem; you can connect locally using the ORACLE_HOME and ORACLE_SID environment variables, which is fine.
When you use the connect user1/user1#orcl version, the orcl is not your SID; as explained in the documentation it is an 'Oracle Net connect identifier'.
connect_identifier
An Oracle Net connect identifier. The exact syntax depends on the
Oracle Net configuration. For more information, refer to the Oracle
Net manual or contact your DBA. SQL*Plus does not prompt for a service
name, but uses your default database if you do not include a connect
identifier.
So you are connecting over a network connection, even though its to the same host, rather than internally using IPC. You don't even need to have ORACLE_SID set when you do that, because that is used for IPC and isn't part of the network connection.
Now, the connect identifier may well actually be the same string as your SID, but it doesn't have to be. Usually when you're using a single term like orcl you're using a 'net service name' which is defined in your tnsnames.ora file. (Depending on how the naming methods are configured in your sqlnet.ora, which determines how the connect identifier is resolved; but this is still the most common configuration I think).
The Oracle Net configuration can be configured using the netca configuration assistant, as the oracle user, though you can create a private tnsnames.ora to override that.
See the Oracle Net admin guide for more about how connectivity works and is configured, and the SQL*Plus user guide for a shorter version.
In order for your user1/user1#orcl connection to work you would need a tnsnames.ora entry looking something like:
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL=tcp)(HOST=my_host)(PORT=1521))
(CONNECT_DATA = (SERVICE_NAME = orcl)))
... where my_host is the DNS name or IP address of your Oracle server, and 1521 is the port the listener is configured to run on. (The listener has to be running for you to be able to connect this way, too). The SERVICE_NAME is not necessarily the same as your SID either, but depends on the database configuration; the lsnrctl status command will show what service names are available.
The ORA-12154 error is telling you that you either don't have a tnsnames.ora file at all, or that it doesn't contain an entry for the alias orcl.
As #a_horse_with_no_name points out, there are other forms of connect identifier, and you don't necessarily need a tnsnames.ora file for a network connection; the options are explained here. I've just focused on the one you were trying to use. You don't necessarily need to use any of them though since you are able to connect locally.

Related

Communication between two databases (Oracle, VirtualBox)

Currently I am trying to understand how can two databases communicate to each other (for instance: get data from one to another).
Detailed description
I have two Oracle databases, one on Windows and latter on Oracle VirtualBox. On Windows DB I have one user (PAI) with single table called TESTME. On VirtualBox, only user (PAI_VB) was created. Now, I want to display the content of the TESTME table from SQL Developer from VB.
I have done
I want to display table TESTME using LINK statement:
CREATE DATABASE LINK LINK_TO_PAI
CONNECT TO PAI IDENTIFIED BY PAI
USING 'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=myIP)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=XE))';
Note: data from 'DESCRIPTION' section were taken from tnsname.ora file on Windows.
Having that, via following query I will manage to display table:
SELECT * FROM PAI.TESTME#LINK_TO_PAI;
Unfortunately, it does not work.
Error from console
ORA-12154: TNS:could not resolve the connect identifier specified
12154. 00000 - "TNS:could not resolve the connect identifier specified"
*Cause: A connection to a database or other service was requested using
a connect identifier, and the connect identifier specified could not
be resolved into a connect descriptor using one of the naming methods
configured. For example, if the type of connect identifier used was a
net service name then the net service name could not be found in a
naming method repository, or the repository could not be
located or reached.
*Action:
- If you are using local naming (TNSNAMES.ORA file):
- Make sure that "TNSNAMES" is listed as one of the values of the
NAMES.DIRECTORY_PATH parameter in the Oracle Net profile
Questions
Could you please propose solution to my problem (I know that in *Action section there is a hint but still I cannot solve it).
Maybe, you could introduce me another way to make communication between two databases possible.
EDIT
I managed to connect from my VB machine to one on Win10 via SQLDeveloper and SQLPlus. Unfortunately, using Oracle LINK I can not access data from database.
SOLVED !!
I managed to solve my issue. The problem laid in LINK. Since following part:
'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=myIP)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=XE))'
was inside tnsnames.ora file i should define my link as follows:
CREATE DATABASE LINK LINK_TO_PAI
CONNECT TO PAI IDENTIFIED BY PAI
USING 'xe';
After that minor change, I was able to freely us LINK in my example. Cheers :)
Here's what you need to have for a working database link:
Network connectivity between the two hosts.
Oracle Listener process running on the host you want to connect to.
Correct TNS entry while creating the link.
Correct username and password to connect to the remote database.
The TNS-12154 error you're getting means the database running on the virtual host can't get to XE's listener using the description you gave it.
Make sure you're using the correct IP address when trying to connect to your Windows host from your virtual machine.
Run tnsping from your virtual environment to see if it can get to the Windows host listener.
tnsping 'DESCRIPTION = (ADDRESS=(PROTOCOL=TCP)(HOST=your_windows_host_ip_from_step_1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))'
or just tnsping XE if you have the TNS entry stored as XE in tnsnames.ora file on your virtual machine.
See also: Oracle documentation — Testing Connections.
Once you get OK response from tnsping try connecting to XE with sqlplus (sqlplus PAI/PAI#XE) or via SQL Developer running on the virtual host. If you can connect that way your database link should also work with the same TNS entry.
This is a tricky part of oracle because there are a number of diverent ways to make a connection.
I suggest that you begin to make sure that you have a tnsnames.ora file both on windows and in your virtualbox environment. What os are you running in VirtualBox by the way?
In both tnsnames.ora files both databases should be named. Easiest to make them identical.
Then connect with sql*plus from windows to your database in VirtualBox and from VirtualBox to your database on Windows.
Just to make sure your network and tns config are OK.
If this works recreate your db-link with the servce alias from tnsnames after using. This should work.

Error while connecting to Oracle Server from Instant client through CMD prompt, but SQL Developer connects?

I am using Client provided laptop (windows XP professional 2002) and do not have administrative privileges (hence cannot st any required environment variables as well):
SQL Developer is provided and I am able to access the oracle server xaal5#:1521/ from SQL developer,
I need to use SQL LOADER to perform some heavy loading. I decided to download the instant client to see if I can save some time while my oracle client installation requests takes ages to go through approvals.
I went to the link: http://www.oracle.com/technetwork/topics/winsoft-085727.html
for Windows and downloaded the following Instant Client Downloads for Microsoft Windows (32-bit)
Version 10.2.0.4
Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
Download instantclient-basic-win32-10.2.0.4.zip (34,742,358 bytes)
*Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client
Download instantclient-sqlplus-win32-10.2.0.4.zip (725,418 bytes)
Extracted these two zip files into C:\instantclient-win32 folder, got the following files (Yes there is no SQL LOADER in it , but i decided to first set the oracle client up and then look for SQL LDR)
sqlplus.exe
oci.dll
ocijdbc10.dll
ociw32.dll
orannzsbb10.dll
oraocci10.dll
oraociei10.dll
Orasqlplusic10.dll
classes12.jar
ojdbc14.jar
glogin.sql
I Ran the following CMD prompt of windows machine:
sqlplus xaal5#:1521/SID
and got the following error :
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
I created a tnsnames.ora file with following entry:
PLMS = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXXXXX)(PORT = 1521))
(CONNECT_DATA =
(SID = sblcusdv)
))
and set up a USER VARIABLES to point to the path of tnsnames.ora file (in the Environment variables window) , as i cannot create a system variable.
$TNS_ADMIN=C:\instantclient-win32
I Ran the following CMD prompt again:
sqlplus xaal5#:1521/SID
and got the following error, again :
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
What am i doing wrong !! or is there another way to get SQL loader working on my system considering the constraints (long wait for approvals for oracle client installation).
When you use this format:
sqlplus xaal5#HOST:1521/SID
... you're using the 'easy connect' syntax, bypassing the tnsnames.ora and connecting to the service name SID - I assume you're actually using the SID from your TNS file, /sblcusdv. The SID and service name are not always the same thing, and the error indicates they are different in this environment.
To use your tnsnames.ora entry, use this syntax:
sqlplus xaal5#PLMS
That is, with the TNS alias you defined. If you don't want to use that file you need to know the service name. From the server you can use lsnrctl services to see which service names are registered, but you might not have access. If you have permissions you can do show parameters service_names from SQL*Plus (while connected via TNS), or you can query the performance views to get that information. But your account may not have access to that information either. In which case you'd need to ask your DBA. (I'm also assuming SQL Developer is connecting by SID, but it's possible it is using the service name, so you can just copy that).
sqlplus xaal5#//HOST:1521/SERVICE_NAME
You can't use SQL*Loader from the imstant client though, so you still have to wait for the full client to be installed. You might want to look at external tables as an alternative to SQL*Loader; then you could stick to instant client (or indeed SQL Developer). But you'd need to be able to get the data files into a DB-recognised directory on the server, which might haveits own issues.
You have to use the Description as stated.
sqlplus Username/Password#description
In your case:
sqlplus Username/Password#PLMS
This should be sufficient, no need to mention hostname or Port.
In case it doesn't work, check if your System variable PATH contain the oracle installation folder at first place. And when you have Oracle DB and Oracle Client installed on same machine, look if both TNSNAMES have the connection you looking for.

I can access my oracle database by command line, but cannot by navicat, ORA-12514 error

I use the command prompt to connect my Oracle database. All functions work, but when I try to use my Navicat to connect to the database, it shows the following error message:
ORA-12514:TNS:listener does not currently know of service requested in
connect descriptor.
My general settings for Navicat are:
host type:basic
ip address:127.0.0.1(also try my ip, but still have same problem)
port:1521
service name:orcl
By "all functions work", I assume you mean you are able to connect to the database and query.
Can you show us the connect that you use.
If you are using sqlplus in this fashion,
sqlplus userid/password#database1
it means your current client is pointing to the correct tnsnames.ora. May be navicat does not point to the correct tnsnames.ora file? The error indicates that you want to connect to, say database1, and Oracle is not able to map "database1" to the correct server, host and port number.
Have you gone through the connectiond details here?
http://www.navicat.com/en/products/navicat_oracle/oracle_detail_win.html
What is your operating system version and oracle version?

Oracle database connections - what are all the fields I need to fill in?

I'm used to using SQL Server and I'm now faced with connecting to Oracle. Can I get some completely unambiguous descriptions for what all the fields I need to fill in are?
Specifically, I want to understand what these are:
Home
Hostname
Port
SID
Service name
Network Alias
Connect identifier
My basic understanding is that hostname is the pooter it's sat on, but is this different to home?
Port is the TCP port and it defaults to 1521 - that seems pretty clear.
I only need to provide either SID or service name? And what's the difference - why one or the other?
If I have a TNS file, what is the network alias and connect identifier? Are these in anyway the same as the other fields I have if I don't use a TNS file?
Sorry to be such a noob, but my preliminary searching to get answers still has me very confused.
Thanks!
Home: ORACLE_HOME, an environment variable that points to the location
of the Oracle binaries (either location Instance runs from on server or client
runs from on client)
Hostname: name of the server
Port: Port on which the Listener is listening for Oracle connections
SID: **S**ervice **ID**entifier. The name of the the Database. This is
one of the identifiers that the Listener will expose
Service name: An alternate identifier that may be exposed by the Listener
On an existing, configured site the easiest way to find these details is from a tnsnames.ora file on a client (or server) from which connections can be made to the Database. Look under $ORACLE(underscore)HOME/network/admin. Find the ORACLE(underscore)HOME with a set (Windows) or env (Unix) command. The tnsnames.ora might also be in a location pointed to by the variable $TNS_ADMIN.
If a tnsnames.ora cannot be found and you have access to the server try the following command, generally as user Oracle
lsnrctl status
lsnrctl is the Listener. Status will show SIDs and Service Names it knows of (and a couple of other details)
Or find the files listener.ora and sqlnet.ora under $ORACLE_HOME/network/admin or in the location pointed to by the env variable $TNS_ADMIN
Generally there will be one listener per host, therefore one Port per host (there could be more but its not common)
To connect to Oracle you have to point the client to the Listener at a location specified by a Hostname/Port combination and tell it which SID or Service to connect too.
DCookie's comment about SID versus Service name is essentially correct.
The SID can be found with (depending on version)
select db_unique_name from v$database
or
select db_name from v$database
Or by looking in the file $ORACLE_HOME/dbs/init(SID NAME).ora or by doing
ps -ef | grep pmon
and noting the last part of the process name, e.g. ora(underscore)pmon(underscore)SID
If you are using Oracle 10g or above, use Easy Connect syntax:
//servername/dbname
, as in:
sqlplus scott/tiger#//servername/dbname
If you need to use TNS, here's the example of TNSNAMES.ORA:
XE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = XE)
)
)
In CONNECT_DATA, you can use either SERVICE_NAME (which is an identifier for an instance registered with a listener), or SID (which is a database identifier).
In a couple of words:
SERVICE_NAME is an identifier of an instance: a running Oracle executable which you will connect to
SID is an identifier of a database: a set of files your data are stored in.
One database can be used by multiple Oracle instances.
When in doubt use SERVICE_NAME.
In this case, connect as following:
sqlplus scott/tiger#XE

Cannot Connect with TOAD but Can with Other Tools/Apps

I am able to connect to an Oracle database using several tools, but am unable to connect using Toad for Oracle 8.5.3 (though before a login/logout to Windows I was able to).
I am not using TNSNAMES.ORA to connect. I have two Oracle homes:
C:\Oracle\product\10.2.0\client_1
(OraClient10g_home1) and
C:\Oracle\product\10.2.0\client_2
(ODACHome2)
where client 2 was installed after client 1.
I have tried Toad with each home, but I get "ORA-12154: TNS:could not resolve the connect identifier specified" when I supply the database name, user name, and password. I can connect using SQL*Plus using this same information, and I can connect via ADO.NET (ODP.NET). tnsping (client 2) to the server works, but tnsping (client 1) does not.
My PATH environment variable contains, in order:
C:\oracle\product\10.2.0\client_2\bin;C:\oracle\product\10.2.0\client_1\bin
and changing the order of PATH seems to have no effect. When I added the line
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES)
to sqlnet.ora of client 2, Toad still could not connect, but the error message appeared much more quickly.
I found the answer rather quickly after I posted, but I don't know if this is the best solution. I copied the ldap.ora file from client 1 to client 2. ldap.ora had lines like the following, which I have munged for security reasons:
DIRECTORY_SERVERS= (XXXXX:389:636,YYYYY:389:636)
DEFAULT_ADMIN_CONTEXT = ""
DIRECTORY_SERVER_TYPE = OID

Resources