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

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.

Related

SQLPLUS: How to connect using default service SYS$USERS

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.

TNS: Listener does not currently know of service requested in connect descriptor

I am able to connect to database using sqlplus /nolog but SQL Developer throws the below error when I connect to it
here are my configuration in tnsnames.ora
and listener.ora
SQL /nolog does not connect to database.
If you are able to connect using conn then need to see parameter passed while connecting database in SQL developer
Which connection type are you using while connecting using SQL developer?
Are you having multiple oracle homes on the server if yes then check which home you are pointing to.

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

I am able to connect to the Oracle Database thru sql plus but not thru sql developer

I installed Oracle11g XE for windows32.
First time when I try to connect via SQL developer it gets connected effortlessly. But once I close the SQL Developer and restart it, then again I am unable to connect to the DB.
Then I tried to connect with SQL plus and guess what it gets connected!
But through SQL devloper I receive an error message as follows:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor.
I have checked all the credentials thoroughly. Still am unable to find the error. Please Help.
When you are using sql plus you use the tnsnames.ora file to find your connection. You can do the same in sql developer.
Just click the listbox connection type and choose TNS instead of basic
then for network alias you should be able to choose a connection from your tnsnames.ora

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