如何在 Node.js 项目上使用 odbc-pool

问题描述 投票:0回答:1

我正在尝试使用一个简单的 Node.js 程序访问 Windows 上的 DSN,该程序返回肯定消息或否定消息。但是,我不断收到以下消息。

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!

遵循我的完整代码:

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));

我正在尝试从 Progress OpenEdge 数据库获取数据并在 Node.js 中使用它。这是我第一次与这两个工具交互。

我正确安装了节点和我在程序中使用的库(

npm install odbc
npm install odbc-pool
),我相信我也正确设置了Progress ODBC,因为当我测试连接时它返回一个积极的消息,但是我认为甚至我看待问题的方式也可能是错误的。

node.js odbc openedge progress-db
1个回答
0
投票

我相信我有一个解决问题的方法,女巫正在使用 odbc/lib/Pool 代替,我执行了

npm install odbc
,在安装的文件中有“lib/Pool”,它似乎包含执行我的意图所需的工具.

© www.soinside.com 2019 - 2024. All rights reserved.