SQLPLUS: How to connect using default service SYS$USERS - oracle

We have a legacy code which connectes to Oracle DB using SQLPLUS command:
sqlplus "$USERNAME/$PASSWORD#//$HOST:$PORT/$SERVICE_NAME"
Values of variables USERNAME, PASSWORD, HOST, PORT and SERVICE_NAME are configured using external properties file. This code works when we have the DB with the service name. In our case DB has default serice:
SYS_CONTEXT('USERENV','SERVICE_NAME')
-------------------------------------
SYS$USERS
DB has only the SID:
SYS_CONTEXT('USERENV','SID')
----------------------------
521
Is there any way to connect to Oracle DB using default service name? e.g.
sqlplus "$USERNAME/$PASSWORD#//$HOST:$PORT/SYS$USERS"
It fails with error:
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
WE also tried with SID as:
sqlplus "$USERNAME/$PASSWORD#//$HOST:$PORT/521"
It fails with error:
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
There is no scope to change code of this legacy app or change DB to add service names. Please let me know if there is any to resolve this issue.

You are mis-using sys_context to determine the correct values for SERVICE_NAME or SID. This is not what SYS_CONTEXT is reporting. The "sid" here is your session_id, not the database's system id. I'm not sure exactly what SYS.USERS represents in this context, but it is certainly NOT a service name by which you connect to a database. You should look at v$parameter:
select name, value from v$parameter where name='service_names';
Or better, just look at the output of 'lsnrctl status' to show you what the listener _does_ know.
I have never seen a listener serving SYS$USERS.

Related

How to find the SID of an Oracle Database using SQL Query

I am developing an app and have a working connection to a Oracle Database using a Connection String like this:
"Data Source=(DESCRIPTION=(ADDRESS=(COMMUNITY=tcpcomm)(PROTOCOL=TCP)(HOST=mydatabasehost.myserver.com)(PORT=1529))(CONNECT_DATA=(SERVICE_NAME=code123.myserver.com))); User Id=user;Password=123456;";
I checked and I can also connect to this database using Oracle SQL Developer on my laptop.
Now I am trying to connect to an Oracle Database using Azure Logic Apps Oracle Connector.
But it requires:
serverhost:port/sid
I tried only serverhost:port but it also does not connect, gives this an error like this:
Test connection failed. Details: Oracle: ORA-12154: TNS:could not
resolve the connect identifier specified inner exception: Oracle:
ORA-12154: TNS:could not resolve the connect identifier specified
clientRequestId:
I tried these 3 queries:
select distinct sid from v$mystat;
select * from global_name;
select value from v$parameter where name='service_names';
But none of the returned values worked locally when I select SID.
I get
Invalid Username/password; logon denied
On Logic Apps this error appear:
Failed to create connection for connection id
'/providers/Microsoft.PowerApps/apis/shared_oracle/connections/shared-oracle-....'.
Encountered internal server error from Data Transfer Service. The
tracking Id is '...'.
Locally, if I use the SERVICE_NAME then it works. But in order to use the Logic Apps connector I need the SID.
I checked the On-premises data gateway Network ports test and it says:
How can I find out the SID by typing a SQL Query into my existing Oracle Connection on Oracle SQL Developer? Or how can I connect from Azure Logic Apps using the SERVICE_NAME?
Is it possible that the server is not accepting connections using the SID, and only accepts connections using the Service Name?
My first answer was lame. You are getting this error:
ORA-12154: TNS:could not resolve the connect identifier
So, it is trying to look up your server in a tnsnames.ora file rather than use host, port, sid or service name. It could be that there is another option that lets you type all that in. Or you may need to install an oracle client and setup a tnsnames.ora entry for your target server.
tnsnames.ora entry would look something like this:
MYSERVER=
(DESCRIPTION=(ADDRESS=(COMMUNITY=tcpcomm)(PROTOCOL=TCP)
(HOST=mydatabasehost.myserver.com)(PORT=1529))(CONNECT_DATA=
(SERVICE_NAME=code123.myserver.com)))
Bobby
You can find the SID by querying the v$thread view in the existing Oracle SQL Developer connection:
If ORACLE_SID = DB_SID
SQL> select instance from v$thread;
INSTANCE
----------------
DB_SID
More info on DB_NAME and ORACLE_SID here
You can query the Oracle SID with the query
SELECT sys_context('userenv','db_name') FROM DUAL;
It is accessible by every user, you don't need special privileges to use it.

Not able to create a DB link

I am trying to create a db link by giving this command
CREATE DATABASE LINK dblink
CONNECT TO qqitsmrep_read IDENTIFIED BY etl#t0pread
USING '(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=pldbitsr0031vm.bmwgroup.net)(PORT=1708))
(CONNECT_DATA=(SERVICE_NAME=ITSM Reporting))
)';
but not sure the service name is correct or not and also when i test the db link i get the below error
The connection looks like this
SQL Developer connection says that
Host is pldbdco0024vm.bmwgroup.net, but you used pldbitsr0031vm.bmwgroup.net
DCODB is SID, while you used Service Name which doesn't seem to be correct
Port is 1595, while you used 1708
Basically, you should check what TNSNAMES.ORA says (or ask your DBA).
Try
CREATE DATABASE LINK dblink
CONNECT TO qqitsmrep_read IDENTIFIED BY etl#t0pread
USING '(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=pldbdco0024vm.bmwgroup.net)(PORT=1595))
(CONNECT_DATA=(SID=dcodb))
)';

Ora-12514 TNS: Listener Error from Oracle Net Configuration Assistant

I am installing Oracle 11.2.0.4 database server per an installation procedure. After installing, I create a database named SM3DDB using Database Configuration Assistant. After creating database, I am able to log into database using Start->Application Development->SQL Plus with following details;
username: sys as sysdba
password: system
While logged in I successfully query name of database using
select name from v$database;
and get the database name:
SM3DDB
The next step of my installation procedure is to configure an Oracle Net Service by using Oracle Net Configuration Assistant with following steps:
Select Local Net Service Name configuration
Add
Enter Service Name in this case I used SM3DDBSRVC
Select TCP
Enter Computer Name and Select Next
Select Yes, Perform a Test
I then get following error:
Connecting...ORA-12514: TNS:Listener does not currently know of service requested in connect descriptor. The test did not succeed.
Next I select change login and I try the test again using
username: sys
password: system
But I still get same error. I repeated the test a few times using sys as sysdba, system, etc for username, but still getting same error. Note that I am able to successfully log in to database using SQL Plus.
Why do I receive this error from Oracle Net Configuration Manager.
Thanks!
The service provided should be the database service name-also given on the window attached below- which is SM3DDB, you will be asked to provide Net Service Name after the test step.
Database service name can be obtained using following method.
SQL> show parameter service
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string ORCL

Unable to connect to oracle with different OS user accout

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.

Oracle EasyConnect connection string using a SID?

I'm trying to connect to an Oracle database through code (Ruby/DBI, but that's irrelevant) using an EasyConnect connection string. All of the Oracle documentation says to specify the connection string as //hostname:port/service_name. I don't have a service_name for the database that I need to connect to, I have a SID instead. Is there a way to create an EasyConnect connection string using a SID instead of a service name?
My connection code looks like this:
DBI.connect("DBI:OCI8://localhost:9000/the_sid", "username here", "password here")
I keep trying different things, and depending on what I try, I get one of two error messages:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor (DBI::DatabaseError)
ORA-12154: TNS:could not resolve the connect identifier specified (DBI::DatabaseError)
Did you try the SID as the SERVICE name? You can usually specify a SID where a service is asked for. SERVICE_NAMES typically defaults to the SID. At a SQL command prompt, enter:
SQL> show parameter service
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string sid
SQL>
The value(s) in the VALUE column is/are the service name(s) the database is registered as.

Resources