Oracle EasyConnect connection string using a SID? - oracle

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.

Related

Not able to login to Oracle db from other user

I am not able to connect with other user except using sys as sysdba. I am giving an error ORA-12154
While tnsping is working and trace route is also working.
sqlplus devtest#p7ru01.ab.com
Sqlplus 19.0.0.0.0
Enter password
Error
ORA -1254 :TNS could not resolve the connect identifier specified
But I am able to login to db using sysdba, but not other db user.
It appears you incorrectly transcribed the output instead of copying and pasting. The error code associated with ':TNS could not resolve the connect identifier specified' is ORA-12154, not 'ORA -1254'.
That said, the net is full of references to ORA-12154, including my own article on it, here.
In short, it could not resolve 'p7ru01.ab.com' to an actual connect string - host name or IP address, port number, and database service name. Either it couldn't find an entry for 'p7ru01.ab.com' in the tnsnames.ora file, or it could not locate a tnsnames.ora file.

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.

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.

Not able to make new oracle db connection in sqldeveloper

While I am able to connect through SQL PLUS using 'system' user. A bit while connecting in SQL Developer it is throwing the error:
Status: Failure - Test failed: Listener refused the connection with the following error: ORA-12505, TNS: listener does not currently know of SID given in...
Value you're inserting into SQL Developer's SID field enter into its Service Name field.

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

Resources