Skip to content

Commit d0122e3

Browse files
committed
Update connect string doc
1 parent b09373f commit d0122e3

File tree

1 file changed

+97
-51
lines changed

1 file changed

+97
-51
lines changed

doc/api.md

Lines changed: 97 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ For installation information, see the [Node-oracledb Installation Instructions][
360360
- 14.1.3 [Optional Oracle Client Configuration](#oraaccess)
361361
- 14.2 [Connection Strings](#connectionstrings)
362362
- 14.2.1 [Easy Connect Syntax for Connection Strings](#easyconnect)
363-
- 14.2.2 [Net Service Names for Connection Strings](#tnsnames)
364-
- 14.2.3 [Embedded Connection Strings](#embedtns)
365-
- 14.2.4 [JDBC and Node-oracledb Connection Strings Compared](#notjdbc)
363+
- 14.2.2 [Embedded Connect Descriptor Strings](#embedtns)
364+
- 14.2.3 [Net Service Names for Connection Strings](#tnsnames)
365+
- 14.2.4 [JDBC and Oracle SQL Developer Connection Strings](#notjdbc)
366366
- 14.3 [Connections and Number of Threads](#numberofthreads)
367367
- 14.4 [Connection Pooling](#connpooling)
368368
- 14.4.1 [Connection Pool Sizing](#conpoolsizing)
@@ -6849,64 +6849,86 @@ The `oraaccess.xml` file has other uses including:
68496849

68506850
### <a name="connectionstrings"></a> 14.2 Connection Strings
68516851

6852-
The `connectString` parameter for
6853-
[`oracledb.getConnection()`](#getconnectiondb) and
6854-
[`oracledb.createPool()`](#createpool) can be an
6855-
[Easy Connect](#easyconnect) string, or a Net Service Name from a
6856-
local [`tnsnames.ora`](#tnsnames) file or external naming service, or
6857-
it can be the SID of a local Oracle database instance.
6852+
The `connectString` property for [`oracledb.getConnection()`](#getconnectiondb)
6853+
and [`oracledb.createPool()`](#createpool) can be one of:
68586854

6859-
The `connectionString` property is an alias for `connectString`.
6860-
Use only one of the properties.
6855+
- An [Easy Connect](#easyconnect) string
6856+
- A [Connect Descriptor](#embedtns) string
6857+
- A [Net Service Name](#tnsnames) from a local [`tnsnames.ora`](#tnsnames) file or external naming service
6858+
- The SID of a local Oracle database instance
68616859

68626860
If a connect string is not specified, the empty string "" is used
68636861
which indicates to connect to the local, default database.
68646862

6863+
The `connectionString` property is an alias for `connectString`.
6864+
Use only one of the properties.
6865+
68656866
#### <a name="easyconnect"></a> 14.2.1 Easy Connect Syntax for Connection Strings
68666867

6867-
An Easy Connect string is often the simplest to use. With Oracle Database 12 or later
6868-
the syntax is:
6868+
An Easy Connect string is often the simplest to use. For example, to connect to
6869+
the Oracle Database service ``orclpdb1`` that is running on the host
6870+
``mydbmachine.example.com`` with the default Oracle Database port 1521, use:
68696871

68706872
```
6871-
[//]host_name[:port][/service_name][:server_type][/instance_name]
6872-
```
6873+
const oracledb = require('oracledb');
68736874
6874-
Note that old-school connection SIDs are not supported: only service names can be used.
6875+
const connection = await oracledb.getConnection(
6876+
{
6877+
user : "hr",
6878+
password : mypw, // mypw contains the hr schema password
6879+
connectString : "mydbmachine.example.com/orclpdb1"
6880+
}
6881+
);
6882+
```
68756883

6876-
For example, use *"localhost/XEPDB1"* to connect to the database *XE* on the local machine:
6884+
If the database is using a non-default port, for example 1984, the port must be
6885+
given:
68776886

6878-
```javascript
6887+
```
68796888
const oracledb = require('oracledb');
68806889
68816890
const connection = await oracledb.getConnection(
68826891
{
68836892
user : "hr",
68846893
password : mypw, // mypw contains the hr schema password
6885-
connectString : "localhost/XEPDB1"
6894+
connectString : "mydbmachine.example.com:1984/orclpdb1"
68866895
}
68876896
);
68886897
```
68896898

6890-
For more information on Easy Connect strings see [Understanding the
6891-
Easy Connect Naming Method][17] in the Oracle documentation.
6899+
The Easy Connect syntax supports Oracle Database service names. It cannot be
6900+
used with the older System Identifiers (SID).
6901+
6902+
The Easy Connect syntax has been extended in recent versions of Oracle Database
6903+
client since its introduction in 10g. Check the Easy Connect Naming method in
6904+
[Oracle Net Service Administrator's Guide][17] for the syntax to use in your
6905+
version of the Oracle Client libraries.
68926906

6893-
#### <a name="tnsnames"></a> 14.2.2 Net Service Names for Connection Strings
6907+
If you are using Oracle Client 19c, the latest [Easy Connect Plus][151] syntax
6908+
allows the use of multiple hosts or ports, along with optional entries for the
6909+
wallet location, the distinguished name of the database server, and even lets
6910+
some network configuration options be set. This means that a
6911+
[`sqlnet.ora`](#tnsadmin) file is not needed for some common connection
6912+
scenarios.
68946913

6895-
A Net Service Name, such as `sales` in the example below, can be used
6896-
to connect:
6914+
#### <a name="embedtns"></a> 14.2.2 Embedded Connect Descriptor Strings
6915+
6916+
Full Connect Descriptor strings can be embedded in applications:
68976917

68986918
```javascript
68996919
const connection = await oracledb.getConnection(
69006920
{
69016921
user : "hr",
69026922
password : mypw, // mypw contains the hr schema password
6903-
connectString : "sales"
6923+
connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
69046924
}
69056925
);
69066926
```
69076927

6908-
This could be defined in a directory server, or in a local
6909-
`tnsnames.ora` file, for example:
6928+
#### <a name="tnsnames"></a> 14.2.3 Net Service Names for Connection Strings
6929+
6930+
Connect Descriptor strings are commmonly stored in [`tnsnames.ora`](#tnsadmin)
6931+
files and associated with a Net Service Name, for example:
69106932

69116933
```
69126934
sales =
@@ -6919,6 +6941,20 @@ sales =
69196941
)
69206942
```
69216943

6944+
Net Service Names may also be defined in a directory server.
6945+
6946+
Given a Net Service Name, node-oracledb can connect like:
6947+
6948+
```javascript
6949+
const connection = await oracledb.getConnection(
6950+
{
6951+
user : "hr",
6952+
password : mypw, // mypw contains the hr schema password
6953+
connectString : "sales"
6954+
}
6955+
);
6956+
```
6957+
69226958
Some older databases may use a 'SID' instead of a 'Service Name'. A
69236959
connection string for these databases could look like:
69246960

@@ -6933,60 +6969,71 @@ sales =
69336969
)
69346970
```
69356971

6936-
See [Optional Oracle Net Configuration](#tnsadmin) for where
6937-
`tnsnames.ora` files can be located.
6972+
See [Optional Oracle Net Configuration](#tnsadmin) for where `tnsnames.ora`
6973+
files can be located.
69386974

6939-
For more information on `tnsnames.ora` files, see the [Oracle Net
6975+
For general information on `tnsnames.ora` files, see the [Oracle Net
69406976
documentation on `tnsnames.ora`][18].
69416977

6942-
#### <a name="embedtns"></a> 14.2.3 Embedded Connection Strings
6978+
#### <a name="notjdbc"></a> 14.2.4 JDBC and Oracle SQL Developer Connection Strings
6979+
6980+
The node-oracledb connection string syntax is different to Java JDBC and the
6981+
common Oracle SQL Developer syntax. If these JDBC connection strings reference
6982+
a service name like:
69436983

6944-
Full connection strings can be embedded in applications:
6984+
jdbc:oracle:thin:@hostname:port/service_name
6985+
6986+
for example:
6987+
6988+
```
6989+
jdbc:oracle:thin:@mydbmachine.example.com:1521/orclpdb1
6990+
```
6991+
6992+
then use Oracle's Easy Connect syntax in node-oracledb:
69456993

69466994
```javascript
69476995
const connection = await oracledb.getConnection(
69486996
{
69496997
user : "hr",
69506998
password : mypw, // mypw contains the hr schema password
6951-
connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
6999+
connectString : "mydbmachine.example.com:1521/orclpdb1"
69527000
}
69537001
);
69547002
```
69557003

6956-
#### <a name="notjdbc"></a> 14.2.4 JDBC and Node-oracledb Connection Strings Compared
7004+
Alternatively, if a JDBC connection string uses an old-style
7005+
Oracle system identifier [SID][19], and there is no service name available:
69577006

6958-
Developers familiar with Java connection strings that reference a
6959-
service name like:
7007+
```
7008+
jdbc:oracle:thin:@hostname:port:sid
7009+
```
7010+
7011+
for example:
69607012

69617013
```
6962-
jdbc:oracle:thin:@hostname:port/service_name
7014+
jdbc:oracle:thin:@mydbmachine.example.com:1521:orcl
69637015
```
69647016

6965-
can use Oracle's Easy Connect syntax in node-oracledb:
7017+
then either [embed the Connect Descriptor](#embedtns):
69667018

69677019
```javascript
69687020
const connection = await oracledb.getConnection(
69697021
{
69707022
user : "hr",
69717023
password : mypw, // mypw contains the hr schema password
6972-
connectString : "hostname:port/service_name"
7024+
connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SID=ORCL)))"
69737025
}
69747026
);
69757027
```
69767028

6977-
Alternatively, if a JDBC connection string uses an old-style
6978-
Oracle system identifier [SID][19], and there is no service name available:
7029+
or create a [Net Service Name](#tnsnames):
69797030

69807031
```
6981-
jdbc:oracle:thin:@hostname:port:sid
6982-
```
7032+
# tnsnames.ora
69837033
6984-
then consider creating a [`tnsnames.ora`](#tnsnames) entry, for example:
6985-
6986-
```
69877034
finance =
69887035
(DESCRIPTION =
6989-
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
7036+
(ADDRESS = (PROTOCOL = TCP)(HOST = mydbmachine.example.com)(PORT = 1521))
69907037
(CONNECT_DATA =
69917038
(SID = ORCL)
69927039
)
@@ -7005,8 +7052,6 @@ const connection = await oracledb.getConnection(
70057052
);
70067053
```
70077054

7008-
Alternatively the connection string can be [embedded](#embedtns) in the application.
7009-
70107055
### <a name="numberofthreads"></a> 14.3 Connections and Number of Threads
70117056

70127057
If you open more than four connections, such as via
@@ -7269,7 +7314,7 @@ connections.
72697314

72707315
Pools are added to the cache by using a
72717316
[`poolAlias`](#createpoolpoolattrspoolalias) property in the
7272-
[`poolAttrs`](#createpoolpoolattrs) object::
7317+
[`poolAttrs`](#createpoolpoolattrs) object:
72737318

72747319
```javascript
72757320
async function init() {
@@ -13127,7 +13172,7 @@ Some QBE examples are:
1312713172
### <a name="sodatextsearches"></a> 29.5 SODA Text Searches
1312813173
1312913174
To perform text searches through documents, a [JSON search index][149]
13130-
must be defined. For example::
13175+
must be defined. For example:
1313113176
1313213177
```javascript
1313313178
await collection.createIndex({ name : "mySearchIdx");
@@ -14027,3 +14072,4 @@ When upgrading from node-oracledb version 3.1 to version 4.0:
1402714072
[148]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-C4C426FC-FD23-4B2E-8367-FA5F83F3F23A
1402814073
[149]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-4848E6A0-58A7-44FD-8D6D-A033D0CCF9CB
1402914074
[150]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-7E9034D5-0D33-43A1-9012-918350FE148C
14075+
[151]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-8C85D289-6AF3-41BC-848B-BF39D32648BA

0 commit comments

Comments
 (0)