proc - Connect to remote oracle database - oracle

I'm trying to connect to oracle DB on remote server:
userid = getenv("ORACLE_USER");
oracle_password = getenv("ORACLE_USER_PASSWORD");
db_name = getenv("DB_NAME");
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
I get an error: ORA-01034.
I'd be happy for help. Thanks.

EXEC SQL BEGIN DECLARE SECTION;
userid VARCHAR(50);
oracle_password VARCHAR(50);
db_name VARCHAR(50);
EXEC SQL END DECLARE SECTION;
main()
{
userid.arr = getenv("ORACLE_USER");
userid.len = strlen(userid.arr);
oracle_password.arr = getenv("ORACLE_USER_PASSWORD");
oracle_password.len = strlen(oracle_password.arr);
db_name.arr = getenv("DB_NAME");
db_name.len = strlen(db_name.arr);
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
if (sqlca.sqlcode==0)
{
prnitf("sucessful");
}
else
{
printf("failed");
return;
}
}
Hope it may be useful to you.

You will get ORA-01034 error when the database was not started up.
Possible causes include the following:
The SGA requires more space than was allocated for it.
The operating-system variable pointing to the instance is improperly defined.
Following line may resolve you issues
Check out link

First of all, use the alternative format:
EXEC SQL CONNECT :usr_pwd;
where the host variable usr_pwd contains your username and password separated by a slash character (/).
Then for usr_pwd attach remote server info:
"user/pwd#(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))"
For fast verification, you can use sqlplus to see if it connects first then plug in your code and compile:
sqlplus user/pwd#(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))

Related

Tomcat 9 datasource URL syntax to connect to an oracle DB

Im gonna do a datasource Tomcat 9.0.63 to connect to my Oracle DB.
Actually we use dataguard (2 db, a main one and a backup one)
In the configuration of server.xml file , in order to set the connection, i wonder in the parameter "URL" if i can use the following syntax:
jdbc:oracle:thin:#(DESCRIPTION = (ADDRESS_LIST =(LOAD_BALANCE=off)(FAILOVER=ON) (ADDRESS = (PROTOCOL = TCP)(HOST = HOSTNAMEMAINDB)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = HOSTNAMEBACKUPDB)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = SERVICENAME) (FAILOVER_MODE = (TYPE = SELECT)(METHOD = BASIC)(RETRIES = 120)(DELAY = 5))))
The questio would be if the datasource tomcat would support this syntax
Thank you very much
Ive tried with non Dataguard configuration and that work, i wonder if that would work with this configuration
Yes, it should be a string that is correctly formed. The long form connection string will work.
Another way is to move the entire connection string to a file named tnsnames.ora with a Name-value pair and then use a TNS Alias in the connection URL and TNS_ADMIN pointing to the location of the tnsnames.ora file (jdbc:oracle:thin:#orcldbtest_medium?TNS_ADMIN=/Users/test/). Refer to JDBC developer guide for more details.

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.

TNS:could not resolve the connect identifier specified at OCI call OCIServerAttach

I am working on OBIEE-12c. My db is also Oracle-12c. During repository creation i am getting following error.
[nQsError:17014] Could not connect to Oracle database.
[nQsError:17001] Oracle Error code: 12154, message: ORA-12154:
TNS:could not resolve the connect identifier specified
at OCI call OCIServerAttach.
Have you tried writing the full connection string, as it appears in the tnsnames.ora file, instead of just the name??
Instead of writing pdborcl write:
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = pdborcl))
)
Or whatever your connect string looks like.
I'm not sure why that happens but i couldn't make my work until I did that.
to resolve the issue, try the following
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = <what ever SID you specified>)))
log : anonymous
P/w : < the password you specified when creating the Database>

how to query two different oracle database servers?

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.

ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA

I'm trying to connect my local Oracle 11g database using server explorer in Visual Studio 2010. I tried to setup everything as per instruction, but I'm still getting an ORA-12504 error.
Here is the error:
Here is my tnsnames.ora contents:
# tnsnames.ora Network Configuration File: C:\app\rsahi\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
VENUS =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SPRPRG020)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = VENUS)
)
)
LISTENER_VENUS =
(ADDRESS = (PROTOCOL = TCP)(HOST = SPRPRG020)(PORT = 1521))
listener.ora file contents,
# listener.ora Network Configuration File: C:\app\rsahi\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = SPRPRG020)(PORT = 1521))
)
)
ADR_BASE_LISTENER = C:\app\rsahi
Try this, in Visual Studio's Server Explorer Data Connection panel:
Data source name: SPRPRG020/VENUS
i.e. the Data source name format is SERVER_NAME_OR_IP/DATABASE_NAME
In the "Connection Properties" -> "Advanced" set in the "Data Source" field the information in format HOST/SERVICE_NAME. E.g. 127.0.0.1/TEST
Without having much knowledge in connecting ODP.NET with an Oracle DB, I suggest you start using SERVICE_NAME (e.g: VENUS) in your connection parameters.
Oracle states that:
From 11g onwards, the feature of using the hostname provided in the /etc/hosts file, as the alias / service name has been changed. As a result, the user will have to provide the service name while connecting OR configure the target listener with a default service name.
One way to bypass the SERVICE_NAME client side requirement is to force the Listener always sending you on the same SERVICE by telling it to do so in the tnsnames.ora
DEFAULT_SERVICE_LISTENER = VENUS
But I do not suggest you do that as it's quite restricting.
I have experienced the same problem when I was trying to create LinkedServer with Oracle 11g. My oracle instance name was: PC-2.my.xgen and my listener name was "NB". The last parameter of first statement is actually the concatenation of Oracle server instance and listener name.
So I have write down the following statements in SQL server.
--add a linked server into SQL server
--last parameter contains OracleInstance / Listener Name of desired database
EXEC sp_addlinkedserver 'OracleLinkedServer4', 'Oracle', 'MSDAORA', 'PC-2.my.xgen/nb'
--add login information into linked server
EXEC sp_addlinkedsrvlogin 'OracleLinkedServer4', false, Null, 'system', '123456'
In Oracle database "NB" I have a table named : CRD_CIL_NOTIFICATION_TYPE. So I have written down the following statement to get the records.
select * from OracleLinkedServer4..SYSTEM.CRD_CIL_NOTIFICATION_TYPE
In the "Connection Properties" -> "Advanced" set in the "Data Source" field the information in format HOST:PORT/SERVICE_NAME. E.g. 10.xxx.xxx.xxx:1521/SIDNAME

Resources