【发布时间】: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