0

Im trying to access a DSN on windows with a simple Node.js program that returns either a positive or a negative message. However, I keep getting the following message.

Error connecting to database: TypeError: Pool is not a constructor
    at checkConnection (C:\project\path\server.js:9:16)
    at Object.<anonymous> (C:\project\path\server.js:22:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47
Connection failed!

follows my full code:

const { Pool } = require('odbc-pool'); 

const connectionString = 'DSN=test-dsn-name';

async function checkConnection() {
    let pool;

    try {
        pool = new Pool(connectionString);
        console.log('Connection to OpenEdge database established successfully.');
        return true;
    } catch (error) {
        console.error('Error connecting to database:', error);
        return false;
    } finally {
        if (pool) {
            await pool.close();
        }
    }
}

checkConnection()
  .then(success => {
    if (success) {
        console.log('Connection successful!');
    } else {
        console.error('Connection failed!');
    }
  })
  .catch(error => console.error(error));

Im trying to get the data from a Progress OpenEdge database and use it in Node.js. This is the firs time I interact with both tools.

I properly installed node and the libraries im using in the program (npm install odbc and npm install odbc-pool), I believe that i properly set up the Progress ODBC as well since when i test connection it returns a positive message, however i consider that even the way im looking at the problem might be wrong.

1 Answer 1

0

I believe i have an workaround to the problem witch is using the odbc/lib/Pool instead, i executed npm install odbc, in the installed files there is "lib/Pool" which seems to contain the necessary tools to do what i intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.