Oracle connection test - oracle

We are developing java based web application, which runs on Ubuntu 12.04. At the start of installation, we prompt for Oracle server's Host, Port, user, password & SID details and then passed them to installer to build jdbc:oracle:thin url. Eventually, our installer connects to Oracle and creates some tables.
Now I am trying to write a script(shell or python) to quickly verify user entered Oracle settings are correct or not by simply connecting to Oracle and disconnecting before passing those to our installer. I tried to use echo "exit" | sqlplus -L user/password#//host:port/SID | grep Connected > /dev/null but sqlplus easy connect is only taking service-name not SID.
Is there any easy way to test Oracle connectivity. I need to write it in script, which needs to run automatically as a part of installation steps.
Thanks for all the help.

Read https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:45033135081903
Oracle listener is expected to listen to your request for connection.
Here is the copy of Tom's answer
[tkyte#desktop tkyte]$ sh -vx test.sh
sqlplus
'scott/tiger#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=152
1)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ora9ir2.kyte.com)))'
Use your host, port and service_name.

Related

How to get username/password/hostname/port/SID to establish connection in SQL developer

I installed Oracle database 21c and sqldeveloper. During the installation of oracle database 21c I inputted my password upon the prompt. I tried to key in the password and the given username SYS to create connection in sqldeveloper but I got the error
Status : Failure -Test failed: IO Error: The Network Adapter could not
establish the connection (CONNECTION_ID=9mv7VkLpQniPUhJwegf7OQ==)
I'm trying to create a local database to practice SQL and I'm not looking to connect to an external database. What should I do in order to achieve my goal?
Ok, just do this instructions to connect to the database via sql developer:
1- Startup database (if you do not starttup database yet);
2- In OS prompt execute:
lsnrctl start
The command start your listener up.
3- In OS prompt execute (If you are using linux OS):
echo $ORACLE_SID
ifconfig
The first shows your database sid and the second shows your OS IP. The port is usually 1521.
4- In sql developer inter connection name for example Oracle_conn, username and password and set role for the user.
Then you should enter Ip,Port and Sid you obtained in step 4.
5- Press Test or Connect and Enjoy!

How to find Oracle database connection details

I am new to Oracle DB and have created a new Oracle 12c database. I am creating a new connection through SQLDeveloper and where can I get the connection details? HostName? Port? SID?
I tried connecting using default details given in documentation but got the below error
Test failed: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor>
You really need to give more info if you need help :)
What Server are you using? Linux? Windows?
Post your oratab file (/etc/oratab)
Post your TNS file ($ORACLE_HOME/network/admin/tnsnames.ora)
Post your Listener file ($ORACLE_HOME/network/admin/listener.ora)
Assuming you're using Linux :D
You need to look at the file "/etc/oratab" if you're on Linux.
This will contain your SID.
Your TNS (located in $ORACLE_HOME/network/admin/) should contain the TNS Entry with SID as per your oratab file.
This is an example entry you will find in the oratab file:
orcl:/opt/oracle/product/10.2.0/db_1:Y
The let hand side "orcl" is your SID, and you will use this for your SID in the Oracle TNS.
If you find that your TNS is configured correctly, then the error message you provided may also indicate that your Database was not registered to the Listener.
You may connect to the sql database as follows:
Set your Oracle Environment
$ . oraenv
Prompts for SID: Enter the value "orcl" (if this is your SID?)
now login:
$ sqlplus / as sysdba
This will log you into oracle as a sysdba.
Execute the follwing:
SQL> Alter System Register;
You should notice a confirmation message that the system is altered.
now exit SQLplus, and try again
SQL> exit
On Windows ISTR, to get the SID, look at the running processes and you should see something called "oracleXXX.exe" or similar. The XXX will be your SID.
You should also see a "TNS" or "Listener" process, probably with the same "XXX".
To get the port number, (usually 1521-1526), find the folder where Oracle was installed to "the "Oracle Home") and in there go to the "network\admin" folder. You should see a "listener.ora" file in there, and if you view this is notepad you should be able to figure out what the port is set to.
This file should also tell you what host/network address the listener is attaching to - you use this IP as the "Hostname" in you connection. Sometimes (again I'm a bit cloudy with Oracle on Windows) the listener.ora might be named listnereXXX.ora, with XXX matching the value you will have seen in SID the checks above.
Obviously if you are new to Oracle, do not amend these files.
If you have netstat/wireshark or similar you can see what the port is attached to the TNS/Listener process.
If you have installed it on same machine on which you are running sql-developer then
host: 127.0.0.1
port: 1521
username and password same as you put while installing oracle datatabse.
keep sid blank

connect to oracle which is hosted on different machine

Hi I am working on a project in which we have oracle DB that is hosted on one machine and java application on other machine. both machines have UNIX OS.i want to develop a shell script that will use DB query and generate a report but i dont have any client(SQLplus) installed on both the machine. so let me know how can i connect to DB and where shud i develop scirpt like on DB unix machine or application machine.
sqlplus -s "/as sysdba
this is use of sql plus i dont have on any machine..
if you have ssh access on both the machines you could run virtually any command(through ssh) you could on the machine itself:
ssh user#server1 "ls ~/"
for example the above will give you a listing of files in "user"s home directory on server1..

oracle listener supports no service

I am having trouble with my Oracle instance.
I get the following error when I run lsnrctl stat in command prompt. I even confirmed Oracle services running.
The listener supports no services.
I assume the platform is Windows and the Oracle version is 11g.
When an Oracle database instance starts, it tries to register itself to the default listener or to the listener registered in the init parameters as the local_listener. What you can do is
make sure that your local_listener parameter points to your listener
make sure that your listener runs on localhost port 1521 (using the listener.ora file)
This is when the database is using a dynamic listener. You could also make the listener a static one by entering the instance details in the listener.ora file. Docu about the listener.ora is found here Oracle Net Listener Parameters (listener.ora)
when the listener is created after creation of database,we need to explicitly register our instance.
try:
starting database by doing startup and check the listerner status by lsnrctl status and it your instance is running it means pmon has done registering your instance with the listener itself.
A solution is very simple for this error, first, let's understand why this error occurs. It basically has two reasons which are:
1) Your database and service name is not properly set in Oracle environment it should be same everywhere check below parameter values
-ORACLE_SID in oracle environment.
-Check Database Instance name.
-SID_NAME in tnsnames.ora file.
-SERVICE_NAME in listener.ora file.
2) Host name/IP address is missing, not correct or spelling mistake, so please check the below.
-Check the IP ADDRESS in /etc/hosts file.
-It should be same in listener.ora and tnsnames.ora file
-And it should be able to ping from the local and remote server.
Now see I've also faced the same problem and resolved:
please visit this StackOverflow link:
https://stackoverflow.com/a/45065640/6332029
I hope it will help, thanks!
In my case it was easy - for some reason, after restarting my laptop, services stopped working.
So, Run > services > start OracleService helped to start the listener
I had this problem with the latest Oracle 19c version with CentOS 8 installation.
So there is a bug with this Oracle DB instance.
What happens: When you install the ORACLE DB, it automatically creates the listener with an instance. The problem exist in the Hierarchy File System of Linux and how the permission is distributed between the Sudo User group and the non-oracle User.
What you have to do :
Okay to solve this, you have to open your bash profile
***nano ~/.bash_profile***
this is equivalent to environment variables in Windows.
write text in editor: export ORACLE_HOME=/u01/app/oracle/product/{oracle-version}/dbhome_1
Save & Exit
Execute: export ORACLE_HOME=/u01/app/oracle/product/{oracle-version}/dbhome_1
test the environment variable :
Echo $ORACLE_HOME -- should display result
execute chmod 777 /home
execute chown -R oracle /home
open terminal su oracle && cd /u01/app/oracle/product/{oracle-version}/dbhome_1/bin
with oracle account execute ./lsnrctl start -- it should run with no services still
execute: su {root account} && sudo ./dbstart
it should run run with 1 or 2 error.. its fine as long as it doesn't say "ORACLE_HOME is not set"
go back to execute: su oracle && ./lsnrctl status with non root account
That's it.. it should now connect with your service and handler, should give the instance of your db name to connect with. You can use the sys as sysdba and password during installation to log into the database.
After starting the listener service I had to wait 60 seconds before the services would show up as running. So if you enter "lsnrctl stop" followed by "lsnrctl start" you might have to wait a minute before "lsnrctl status" will show your listener services.
I did check all the things but could not find the cause. So I re-installed the Oracle and using that now.

Installer installing on two machines

I need to create one installer which will install components on two different machines.Windows services and web services on "APP Server" and database part on "DB Server". SQL Server 2005/2008 will be already present on DB SERVER. But it may use different port than default port for sql server.
What things I will require in order to implement this ?
Thanks in advance.
It is simply a matter of bundling a SQL script with the installer and executing the script by calling sqlcmd with ExecWait.
We can run a script using a trusted connection via:
sqlcmd -S _SERVER\_INSTANCE_ -d _DBNAME_ -i _SCRIPT_FILE_
Or with a SQL Login:
sqlcmd -S _SERVER\_INSTANCE_ -d _DBNAME_ -U _USERNAME_ -P _PASSWORD_ -i _SCRIPT_FILE_
For performing actions on remote SQL Server engine native driver is required.In SQL Server 2005 or later the command line client is called sqlcmd.
I suggest to create 2 radio buttons:
(o) Install - App Server
( ) Install - DB Server
User select one item and appropriate components will be installed. (like .dlls, .exes, ... on app server and data files or sql scripts [also scripts can be executed] on db server).
Everything packed into single installer.
Also there should be some custom page(s) (created using nsDialogs) where user can set parameters(port, server name, name of db, path to db, ...)

Resources