You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron+Vue应用连接DB2实例:node-odbc与ibm_db报错排查

Electron应用连接DB2实例遇到的问题

问题1:node-odbc连接后提示连接已关闭

我正尝试使用node-odbc库让Electron应用连接DB2实例,已确认系统ODBC驱动安装正常,在main.js中编写了以下启动时执行的代码:

const conn = "DRIVER=IBM i Access ODBC Driver;SYSTEM=192.168.0.15;UID=myuser;PWD=mypwd;DATABASE=Iasp01"
//IBM i Access ODBC Driver
odbc.connect( conn ).then( (connection) => {
    console.log(connection)            
}).catch( e => console.log(e) )

每次尝试连接时,VS Code控制台输出如下内容:

INFO  Launching Electron...
Connection {
  CONNECTION_CLOSED_ERROR: 'Connection has already been closed!',
  odbcConnection: ODBCConnection {}
}

开发机器处于代理环境,是否需要设置代理,或是遗漏了其他配置?

更新:导入ibm_db库时出现错误

尝试在Electron主进程中导入ibm_db库时,出现以下错误:

TypeError: Cannot read property 'indexOf' of undefined
    at Function.getFileName (webpack:///./node_modules/bindings/bindings.js?:178:16)
    at bindings (webpack:///./node_modules/bindings/bindings.js?:82:48)
    at eval (webpack:///./node_modules/ibm_db/lib/odbc.js?:57:86)
    at Object../node_modules/ibm_db/lib/odbc.js (C:\Users\myuser\Desktop\tool\dist_electron\index.js:1125:1)
    at __webpack_require__ (C:\Users\myuser\Desktop\tool\dist_electron\index.js:20:30)
    at eval (webpack:///./src/background.js?:12:64)
    at Module../src/background.js (C:\Users\myuser\Desktop\tool\dist_electron\index.js:3121:1)
    at __webpack_require__ (C:\Users\myuser\Desktop\tool\dist_electron\index.js:20:30)
    at eval (webpack:///multi_./src/background.js?:1:18)
    at Object.0 (C:\Users\myuser\Desktop\tool\dist_electron\index.js:3144:1)

注:前端基于Vue开发,为解决Electron的一处错误,已将Node 16作为开发依赖安装。

内容的提问来源于stack exchange,提问作者OHICT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 10:52:34