【问题标题】:Using node-adodb with .mdb Access Files将 node-adodb 与 .mdb 访问文件一起使用
【发布时间】:2021-10-24 07:32:02
【问题描述】:

我正在尝试在 Windows 操作系统上编写一个容器化的 Node 应用程序,该应用程序接收 Microsoft Access 数据库并访问其中的数据。我希望使用 npm node-adodb 与 Access 进行交互。

我的应用程序与 .accdb 访问文件完美配合。当我尝试连接到 .mdb 访问文件时,我收到此错误 Spawn C:\Windows\SysWOW64\cscript.exe error, Provider cannot be found. It may not be properly installed。我的代码在我的本地 Windows 计算机上运行,​​所以我猜测这与我的容器环境的设置方式有关。

我这样设置基础 Dockerfile:

# Get base Windows OS image
FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Set environment variables
ENV NPM_CONFIG_LOGLEVEL info
ENV NODEJS_VERSION 12.9.1

# Download & Install 2010 Access Driver
RUN powershell -Command "wget -Uri https://download.microsoft.com/download/2/4/3/24375141-E08D-4803-AB0E-10F2E3A07AAA/AccessDatabaseEngine.exe -OutFile AccessDatabaseEngine.exe -UseBasicParsing"
RUN powershell -Command "Start-Process -NoNewWindow -FilePath \"AccessDatabaseEngine.exe\""

# Download & Install 2016 Access Driver
RUN powershell -Command "wget -Uri https://download.microsoft.com/download/3/5/C/35C84C36-661A-44E6-9324-8786B8DBE231/accessdatabaseengine_X64.exe -OutFile accessdatabaseengine_X64.exe -UseBasicParsing"
RUN powershell -Command "Start-Process -NoNewWindow -FilePath \"accessdatabaseengine_X64.exe\""

# Download and install Node.js
RUN powershell -Command "wget -Uri https://nodejs.org/dist/v%NODEJS_VERSION%/node-v%NODEJS_VERSION%-x64.msi -OutFile node.msi -UseBasicParsing"
RUN msiexec.exe /q /i node.msi

# Run node
CMD [ "node" ]

我像这样建立访问连接。我如何实例化连接取决于我是在本地环境中还是在线。它在 .accdb 和 .mdb 上也有所不同:

// Define connection string & initialize export connection depending on if it's a .accdb .mdb file
let access;
if ((file.path).substring(Math.max(0, (file.path).toString().length - 5)) === 'accdb') {
    const connStr = `Provider=Microsoft.ACE.OLEDB.12.0;Data Source=${file.path};Persist Security Info=False;`;
    access = ADODB.open(connStr); // This works
} else {
    const connStr = `Provider=Microsoft.Jet.OLEDB.4.0;Data Source=${file.path};`;
    access = ADODB.open(connStr); // This fails
}

是否需要安装其他软件包才能使用 .mdb 文件?我需要以不同的方式连接吗?任何帮助将不胜感激。

【问题讨论】:

    标签: node.js docker ms-access adodb


    【解决方案1】:

    由于错误消息来自“C:\Windows\SysWOW64\cscript.exe”,请确保您已安装 32 位版本的“Microsoft Access 数据库引擎”分发包。

    如果您安装了 64 位引擎包,请像这样打开数据库连接:

    access = ADODB.open(connStr, true);
    

    【讨论】:

    • 抱歉耽搁了,感谢您的帮助。我试过这个无济于事。除了交替布尔第二个参数外,我还尝试在 32 位和 64 位 Access 安装之间交替。我什至尝试在 2010 和 2016 包之间交替使用。这一切都没有运气。我的想法不多了。如果您想到其他任何事情,我会很高兴听到它。
    • 没问题。您是否尝试在 Access 中打开数据库以了解其格式?另外,当您尝试这些不同的组合时,您会看到哪些错误消息?
    • 按格式我假设你的意思是它的数据库模式?如果是这样,格式/模式很好。无论我们安装的是 2010 还是 2016,或者我们安装的是 X32 版本还是 X64 版本,错误消息都保持不变。如果我们像您推荐的那样使用 X64 实例化连接,则错误为Spawn C:\Windows\System32\cscript.exe error, Provider cannot be found. It may not be properly installed。如果我们使用 X32 实例化,错误是我最初报告的,Spawn C:\Windows\SysWOW64\cscript.exe error, Provider cannot be found. It may not be properly installed
    • 我试过你上面贴的 JS 代码。它在我的 Windows 10 PC 上运行良好。我没主意了。 :-(
    • 最糟糕的是它也适用于我的 Windows 10 PC。当我在本地运行它时它工作正常。当我尝试在 Windows Kubernetes 中运行应用程序时出现问题。我的 Kubernetes 操作系统从 mcr.microsoft.com/windows/servercore:ltsc2019 Docker 映像中提取,如果有帮助的话。如果您没有其他想法,感谢您的时间和帮助。如果我弄清楚了,我一定会在这里发帖。
    猜你喜欢
    • 2014-10-07
    • 2023-02-14
    • 2012-02-17
    • 1970-01-01
    • 2017-12-02
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    相关资源
    最近更新 更多