简体   繁体   中英

How to use expire_time parameter with the Node.js node-oracledb?

Sample Code

try {
    const oracledb = require('oracledb');
    const express = require('express');
    const app = express();

    // Memorized Connections
    var allDBSessions = {};

    app.get('/', (req, res) => {
        const dbConfig = {
            user: 'vph_dev_ad_gss_tran',
            password: 'Gsstpl100'
            // ,connectString: '//IP:PORT/SERVICE_NAME' // Working as Expected
            ,connectString: '//IP:PORT/SERVICE_NAME?expire_time=1' // Minutes // Not Working
            // ,connectString: '//IP:PORT/SERVICE_NAME?connect_timeout=15' // Seconds // Not Working
            //  Your connection string could be "mydbmachine.example.com/orclpdb1?expire_time=2" // Sample From Node Oracledb Site
        };

        async function ExecuteQuery() {
            try {
                // Getting DB Connections
                let dbInstance;
                if (allDBSessions.first_instance) {
                    // Assigning From Memorized Connections
                    console.log('Connection Available From the Memory');
                    console.log('Connection Created Time - ' + allDBSessions.first_instance.created_time);
                    dbInstance = allDBSessions.first_instance.db_connection;
                    console.log('Connection Assigned From Memory');
                } else {
                    //Creating New DB Instance
                    console.log('Creating New Connection');
                    dbInstance = await oracledb.getConnection(dbConfig);
                    console.log('Connection Created Successfully');
                    // Memorizing the DB Instance
                    allDBSessions.first_instance = {
                        db_connection: dbInstance,
                        created_time: new Date().toLocaleString()
                        
                    }
                    console.log('Connection Stored into Memory');
                }
                
                // Executing Query
                var query = 'select 1 from dual';
                console.log('Executing the Query - ' + query);
                let queryResult = await dbInstance.execute(query);
                console.log('queryResult', queryResult);
                var finalResult = {
                    'Query Result': queryResult,
                    'Usedd DB Session Info': allDBSessions.first_instance
                };
                res.send(finalResult); // Sending Response
            } catch (error) {
                console.log(error, '----- Catch Error in ExecuteQuery()-----');
                res.send(error);
            }
        }

        ExecuteQuery();
    })

    app.listen(3005, () => {
        console.log(`Oracle DB Sample With Expire Timeout`);
        console.log(`server is listening on PORT 3005`);
    })

} catch (error) {
    console.log(error, '----- Catch Error -----');
}

  • Above Sample Throwing Error while trying to make a successful Connection with the Oracle Db which is 19c.

  • Error Shown below

[Error: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor] { errorNum: 12514, offset: 0 }

Please guide me to overcome from this issue...

Thanks In AdvancE...

HaPPy CodinG...

The Easy Connect Plus syntax like '//IP:PORT/SERVICE_NAME?expire_time=1' is usable when the Oracle Client libraries that node-oracledb uses are 19c or later. The database version doesn't matter. See the architecture diagram in the documentation.

Check what client libraries node-oracledb is using by running the example app version.js . It will output something like:

$ node version.js 
Run at: Thu Mar 18 2021 08:17:22 GMT+1100 (Australian Eastern Daylight Time)
Node.js version: v12.21.0 (darwin x64)
Node-oracledb version: 5.2.0-dev
Oracle Client library version: 19.8.0.0.0
Oracle Database version: 19.3.0.0.0

Check your Oracle Client library version is 19 or later.

Update on EXPIRE_TIME:

  • With 18c client libraries it can be added as (EXPIRE_TIME=n) to the DESCRIPTION section of a connect descriptor (in a full connect descriptor string in the app, or in the tnsnames.ora file).
  • With 19c client libraries it can be used via Easy Connect: host/service?expire_time=n .
  • With 21c client libraries it can be used in a client-side (ie Node.js machine) sqlnet.ora.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM