当前位置: 首页 > 工具软件 > open-registry > 使用案例 >

ODBC错误Unable to open registry key Temporary (volatile) Ace DSN for process

晏望
2023-12-01

python的pyodbc与nodejs的odbc链接accdb数据时,connectionString使用

Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=test.accdb

pyodbc抛出错误

pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3894 Thread 0x167c DBC 0x5bf399e8 Jet'. (63) (SQLDriverConnect);
[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3894 Thread 0x167c DBC 0x5bf399e8 Jet'. (63); 
[HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3894 Thread 0x167c DBC 0x5bf399e8 Jet'. (63); 
[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3894 Thread 0x167c DBC 0x5bf399e8 Jet'. (63); 
[HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)")

node抛出错误

(node:16948) UnhandledPromiseRejectionWarning: Error: [odbc] Error connecting to the database
(node:16948) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16948) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

就算connectionString使用(*.mdb)的结果也是一样。使用ProcessMoniter跟踪python和node,发现它们总在读取

HKCU\SOFTWARE\ODBC\ODBC.INI\\Engines\Jet
HKLM\Software\Microsoft\Office\16.0\Access Connectivity Engine\Engines\Jet

估计是本机系统使用windows 10 x64,MDAC 2.8只支持x86,而JET引擎已被ACE引擎替换,pyodbc与node-odbc开发之时,估计仍然采用基于JET的SDK,而使用ADODB.Connection没有这个问题,查看注册表,所有微软的office ODBC驱动全部指向

C:\Program Files\Common Files\Microsoft Shared\OFFICE16\ACEODBC.dll

当然这是猜测,网上python有用odbc链接accdb的例子,运行系统是x86还是x64就不知道,有空装个x86的虚拟机测试一下。

PS:今天有空,装了个x86的虚拟机,这次连ADO也不管用了,跟踪程序N次,发现很多注册表Access Denied提示,于是用管理员权限运行脚本,发现最终抛出Not a valid file name错误,于是用数据库绝对路径,这次OK了,所有python和node的程序都OK了。

Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=test.accdb

改成

Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\www\test.accdb

就行。或者DBQ=./test.accdb也可以。很是无语。

 类似资料: