how to query two different oracle database servers? - oracle

How do I query two different Oracle database servers using a shell script?
How do I handle connecting to two different servers?
I have two different user ID and password.
I know this is not safe to include the id/pw in the shell script file but can you tell me how this is done?
server 1:
s1.mycompnay.com:1587/hr_dev.mycompany.com/HR_DB
server 1:
s2.mycompnay.com:1587/bank_dev.mycompany.com/BANK_DB
my shell script has something this:
sqlplus hr_db/$1 << EOF

You need to ensure that the path between the two servers is open and both servers have a registry in your tnsnames.ora file:
Using your description you would want two entries
HR_DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = s1.mycompnay.com)(Port = 1587))
)
(CONNECT_DATA =
(SERVICE_NAME = HR_DB)
)
)
BANK_DB=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = s2.mycompnay.com)(Port = 1587))
)
(CONNECT_DATA =
(SERVICE_NAME = BANK_DB)
)
)
You already noted that it is bad practice to include the passwords in the script so I don't need to comment on that any further. After you get the entries in and have taken steps to ensure that firewalls are open you can test it by tnsping'ing the DBs:
tnsping HR_DB
tnsping BANK_DB
If those succeed it will tell you such as well as time in MS to return the packets. A failure will be immediately apparent.

Related

'TNS:could not resolve the connect identifier specified' when connecting to oracle instance through cx_Oracle

I have an Oracle instance on a AWS EC2 instance. When I run this in the AWS linux terminal, it is successful.
ubuntu#ip-xxx-xx-xx-xxx:~$ sqlplus user101/pass101#ip-xxx-xx-xx-xxx:1521/XE
However, when I run the same arguments when connecting through cx_Oracle I get a:
"ORA-12154: TNS:could not resolve the connect identifier specified" error
I know some common problems are with the tnsnames.ora file. I've placed that below.
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ip-172-xx-xx-xx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
~
At the moment the full Easy Connect syntax is being interpreted as a TNS entry.
According to the Connect() documentation, you can use your current code if you specify that you are passing the user argument:
If the user parameter is passed and the password and dsn parameters are not passed, the user parameter is assumed to be a connect string in the format user/password#dsn, the same format accepted by Oracle applications such as SQL*Plus.
So this should work:
connection = cx_oracle.Connect(user="user101/pass101#ip-172-xx-xx-xx:1521/XE")
According to the Oracle connection handling documentation, you could also split that out:
connection = cx_oracle.Connect(
user="user101",
password="pass101",
dsn="ip-172-xx-xx-xx:1521/XE",
encoding="UTF-8"
)
Or if you want to use tnsnames.ora then just give that alias as the DSN value:
connection = cx_oracle.Connect(
user="user101",
password="pass101",
dsn="XE",
encoding="UTF-8"
)

Oracle forms: TNS: could not resolve the connect identifier specified

I have oracle Enterprise edition and oracle forms installed on my computer, when i connect to my database from sqlplus and sqldevelopper, it connects without errors, but when i try to connect from oracle forms, it gives me this error:
ORA-12154:could not resolve the connect identifier specified
I have looked online and i read somewhere that it might be because i have more than one oracle client installed on my computer, and the sqlplus uses the right file and oracle forms uses the one that is not right, and i think that is my case, because i have two of the tnsnames.ora file :
in here:
C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora
and in here:
C:\oracle\product\10.2.0\NETWORK\ADMIN\SAMPLE
here is the content of the first tnsnames.ora file:
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = BOUHDID.Home)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
if it's the case, how can i fix this?
You could just set the TNS_ADMIN environment variabele.
This alawys points to the tnsnames.ora directory. And all oracle products look at this variabele.
So you just have to set TNS_ADMIN to:
C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN
I solved my problem by doing these steps:
uninstalled Oracle froms and reports.
uninstalled Oracle dababase with universal installer.
Deleted all the registries and services associated with oracle.
Reinstalled Oracle database.
Reinstalled oracle forms & reports.
copied from my tnsnames.ora file located in
C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN to the tnsnames.ora file located in C:\orant\NET80\ADMIN
this part:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = BOUHDID)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
and it worked like a charm.
Depending on your Oracle_Home variable config, please check if TNS entry is present in the domains folder created while installing oracle forms & reports.
Example: C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\config\fmwconfig\tnsnames.ora

Why I have to use tnsnames.ora in Oracle SQL Developer to connect some database

when I log on some oracle database, I can connect without tnsnames.ora. However, when I try to log on some other database, it reject because of TNS:connection timeout. What is changed? What does TNS file do? Why I have to have this ora file?
Thank you
File tnsnames.ora just resolves your database alias to full databases address.
Assume you have an entry as this:
ORA11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.0)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORA12)
)
)
Then you can start for example SQL*Plus
sqlplus SCOTT#ORA11
or
sqlplus SCOTT#"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))"
It does the same, the first way is just more convenient.

ODBC connection to oracle time-out

I'm new here so I introduce myself, my name is Ettore Giallaurito and my job is in the IT services in Italy.
My question:
I'm trying to connect to an Oracle DB instance through an odbc (System DNS) connections under XP but I get an error ORA1254 TNS:could not resolvethe connect identifier specified.
I'm using oracle instant client 11.2 and I've my tnsnames properly configured, since I can get connected with DBVisualizer using the TNS method.
To be honest I do get connected in this case, but I need to insert the full connect string:
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = repsit01.sit.sor)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = REPSIT01))
)
since it doesn't get me in if I use just the SID, in my case REPSIT01 as showed below.
My tns entry is as follow:
REPSIT01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = REPSIT01))
)
Any help would be much apprecciated.
Thanks in advance Ettore.
Try setting the environment variable TNS_ADMIN to the directory where your tnsnames.ora file resides.

How to use tnsnames.ora in Grails DataSource?

I'm trying to connect to a load-balanced virtual host specified in tnsnames.ora in my Grails application in DataSource.groovy, with no luck - it (obviously) throws an "Unknown Host Specified" exception.
The tnsnames entry looks like this
someServiceName =
(DESCRIPTION_LIST =
(FAILOVER=ON)
(LOAD_BALANCE=ON)
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = someServerName1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = someServiceName1)
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = someServerName2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = someServiceName2)
)
)
)
I can connect to one of the services (someServiceName1 & someServiceName2) by simply setting the values in DataSource.groovy in the usual way, but I don't know how to connect to the load-balanced virtual host.
I've searched around for using tnsnames.ora in Grails but I can't seem to find a particularly "groovy" way of making this work. Any pointers will be appreciated.
P.S. I would prefer a solution where I would still be able to inject the dataSource into my controllers etc.
I think you need to configure a single service with multiple addresses. Then you have to set your datasource URL string to something like this (without the newlines of course):
jdbc:oracle:thin#(DESCRIPTION=
(LOAD_BALANCE=on)
(ADDRESS=(PROTOCOL=TCP)(HOST=someServerName1) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=someServerName2) (PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=theOnlyServiceName)))
Look here and here for references.
You could use
jdbc:oracle:oci:#someServiceName
I use this, notice it's oci, not thin. It works for me.
Just ran into this issue, here's what fixed it for me:
url='jdbc:oracle:thin:#servername:PORT/servicename'
It was the forward slash between the port and the service name that tripped me up. If you use a colon there, it reads it as a SID instead of a service name.
Good luck!

Resources