I have a java based server (Tomcat) that connects to an Oracle database using a JDBC connection. There are multiple ways to connect to the database: SID, TNS name, Service name.
I would like to understand what is the difference between each of these connections and what would be the recommended connection (SID, TNS, or service) if connecting to a clustered database. Here is the TNS name we have for the database:
MY_NICE_TNS_NAME.MY_COMPANY.COM = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = myhostname)(PORT = 1521)) (LOAD_BALANCE = YES) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = MY_NICE_SERVICE_NAME.MY_COMPANY.COM) (FAILOVER_MODE = (TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5) ) ) )
Thanks!
Create a TNS (Transparent Network Substrate) Service Name (also called a Net Service Name) on a computer where an Oracle client is installed if the Tivoli Data Warehouse exists on a remote Oracle server. The TNS Service name is needed to create an ODBC connection between the client and the server.
Oracle SID is the unique name that uniquely identifies your instance/database, whereas the Service name is the TNS alias that you give when you remotely connect to your database, and this Service name is recorded in tnsnames.
JDBC connections can use a TNSnames. ora entry to connect to an Oracle 11.2. 0.3 database. Is an Oracle client needed to be installed on the machine for this to work, or just have a local tnsnames.
Sid= SID(system identifier) is a unique name for an Oracle database instance. Instance Name = it is same as Oracle SID. service name =SERVICE NAMES specifies one or more names for the database service to which this instance connects.
SERVICE_NAME
is a alias to a database instance (or many instances). The main purpose of this is if you are running a cluster. Using this we can connect specific database within a cluster. And other way, using SID
(System IDentifier) we can connect to a database instance, which is a unique name for an Oracle database instance.
In short, SID = the unique name of your DB, SERVICE_NAME = the alias used when connecting.
There are several ways to provide database information like Directly Specified, tnsnames.ora (i.e. TNS name), LDAP Directory, Network Information Services.
A TNS (Transparent Network Substrate) name is the name of the entry in tnsnames.ora
file which is kept in $ORACLE_HOME/network/admin
This file contains the information which is used by the system to connect to oracle database. Using this a client can fetch server associated information transparently. It contains the following information
PROTOCOL HOST IP ADDRESS PORTNO SID or SERVICE_NAME
E.g
mydb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.35.15.1)(PORT = 1521)) (CONNECT_DATA = (SID = mydb))
JDBC drivers connect with a connection string using TNS as follows
System.setProperty("oracle.net.tns_admin", PATH_TO_TNSNAMES.ORA); Class.forName ("oracle.jdbc.OracleDriver"); dbUrl = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST="+IPHOST+")(PORT="+PORT+"))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME="+DBNAME+")))" conn = DriverManager.getConnection(dbUrl, USERNAME, PASSWORD);
Oracle SID is the unique name that uniquely identifies your instance/database where as Service name is the TNS alias that you give when you remotely connect to your database and this Service name is recorded in Tnsnames.ora file on your clients and it can be the same as SID and you can also give it any other name you want.
SERVICE_NAME is the new feature from oracle 8i onwards in which database can register itself with listener. If database is registered with listener in this way then you can use SERVICE_NAME parameter in tnsnames.ora otherwise - use SID in tnsnames.ora.
Also if you have OPS (RAC) you will have different SERVICE_NAME for each instance.
SERVICE_NAMES specifies one or more names for the database service to which this instance connects. You can specify multiple services names in order to distinguish among different uses of the same database. For example:
SERVICE_NAMES = sales.acme.com, widgetsales.acme.com
You can also use service names to identify a single service that is available from two different databases through the use of replication.
In an Oracle Parallel Server environment, you must set this parameter for every instance.
The TNS is the sql*net configuration file that defines datbases address for establishing connection to them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With