当数据库由另一个过程打开时,无法使用PYODBC在网络驱动器上连接到MS Access数据库
我在网络驱动器上使用Python pyodbc
库时,我在网络驱动器上连接MS Access数据库时遇到了困难,当时数据库已经由另一个过程打开。
为了重现错误,我首先用表创建一个前端和后端访问数据库。然后,我在MS Access应用程序中打开前端文件,以便为后端创建.laccdb
文件。然后,我运行以下代码:
import pyodbc
pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=V:\Backend.accdb;')
v:
是共享网络驱动器。这是我收到的错误消息:
pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x85c Thread 0x2e0c DBC 0x92147c28 Jet'. (63) (SQLDriverConnect);
[HY000] [Microsoft][ODBC Microsoft Access Driver] Could not use '(unknown)'; file already in use.
我只有在数据库已经打开时才会出现此错误。当脚本是使用数据库的唯一过程时,没有错误。
这是其他一些信息:
我在本地驱动器上重复上述测试时不会遇到此错误,因此它似乎与网络驱动器上的数据库有关。
我在MS访问“共享”中具有默认的打开模式,因此数据库不应在独家模式下打开。
错误似乎与尝试通过Python脚本连接有关 - 例如,我可以使用MS Access应用程序打开数据库前端 /表,然后在MS Access Application中打开后端文件同时在网络驱动器上没有问题。
我已经在网络目录上读取并编写权限。例如,我可以使用Python脚本在网络目录中创建文件并删除文件。
我尝试调整ODBC驱动程序 /数据库连接字符串,包括仅在读取模式下打开,并明确确保关闭独家模式。这些选项都没有解决问题。
我的用户已按照建议的。
系统信息:
- MS Access 2019 64位
- 64位MS Access ODBC驱动程序
- Python 3.9,使用Anaconda环境 / Anaconda提示来运行脚本
- PYODBC版本4.0.32
任何帮助都将不胜感激。
I am having trouble connecting to an MS Access database on our network drive using the python pyodbc
library when the database is already opened by another process.
To reproduce the error, I first create a front end and back end Access Database with a table. I then open up the front end file in the MS Access Application so a .laccdb
file is created for the backend. I then run the following code:
import pyodbc
pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=V:\Backend.accdb;')
V:
is a shared network drive. Here is the error message I get:
pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x85c Thread 0x2e0c DBC 0x92147c28 Jet'. (63) (SQLDriverConnect);
[HY000] [Microsoft][ODBC Microsoft Access Driver] Could not use '(unknown)'; file already in use.
I only get this error when the database is already open. There is no error when the script is the only process using the database.
Here is some other information:
I do not get this error when I repeat the test above on my local drive, so it seems to have something to do with the database being on the network drive.
I have the default open mode in MS Access to "Shared", so the database should not be opening in exclusive mode.
The error seems to have something to do with trying to connect via a Python script - for example, I can open the database front end / table using the MS Access Application, and then open up the back end file in MS Access Application simultaneously with no problem on the network drive.
I have read and write permission on the network directory. For example, I can create files and delete files in the network directory using Python scripts.
I have tried tweaking the ODBC Driver / Database Connection String, including opening in Read Only Mode, and Explicitly making sure exclusive mode is turned off. Neither of these options fix the problem.
My user has read access to the ODBC registry as suggested here.
System information:
- MS Access 2019 64-bit
- 64-bit MS Access ODBC Driver
- Python 3.9, using Anaconda environment / Anaconda prompt to run scripts
- pyodbc version 4.0.32
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择?
访问数据引擎需要创建并删除该文件夹的权利。
打开数据库文件时,访问是基于“文件”的系统。因此,当第一个用户(或过程)打开该数据库文件时,JET(现在是ACE)数据引擎会创建锁定文件(LDB)。该文件用于管理并发用户(该文件夹中没有服务器系统,代码或进程 - 它是平面Jane Windows文件打开)。
因此,如果服务器上的共享文件夹(或任何地方)不允许用户在该文件夹中创建(和删除)文件,则不会创建LDB锁定和数据碰撞文件,因此将读取数据库仅有的。
当打开文件的最后一个用户(或进程)关闭数据文件时,如果没有OHTER用户活动,则将删除LDB锁定文件。有些确实可以删除删除权限 - 可以保留LDB文件,但即使没有删除锁定(LDB文件)的能力通常会弄乱这一点。
因此,发生的事情是您仅被阅读或经常在公开时“独家”权利。
为了修复,该共享文件夹需要创建并删除Active的权利。而且我在某些情况下看到了,如果给定的特定用户已获得了Speical权利,则LDB文件“ Inherts”相同的权利,并且再次仅读取所有其他用户,或者无法使用数据库。
那么,要使故事越来越短?
该文件夹作为一般规则的所有用户权限都需要创建文件权限,并且需要文件删除权限。当然,在您自己的个人计算机上,这可以正常工作,因为在大多数情况下,您可以完全使用个人计算机上的任何文件夹和文件。因此,您需要打开(放松)该共享文件夹上的安全权限 - 用户需要创建文件权限并删除文件权限。
the best bet?
The access data engine needs CREATE and DELETE rights to that folder.
When you open a database file, Access is a "file" based system. so, when the FIRST user (or process) opens that database file, then the JET (now ACE) data engine creates a locking file (ldb). This file is used to manage concurrent users (there is not server system or code or process running in that folder - it is a plane jane windows file open).
So, if that shared folder on the server (or whereever) does not allow user(s) to create (and delete) files in that folder, then no ldb locking and data collision file can be created, and thus the database will be read only.
When the last user (or process) that opened the file closes the data file, if no ohter users are active, then the ldb locking file is then deleted. Some do get away removing delete rights - and the ldb file can remain, but even that no ability to delete the locking (ldb file) often will mess this up.
So, what occures is you get read only, or often "exclusive" rights upon the open.
To fix, then that shared folder needs to have create, and delete rights active. And I seen in some cases, if the given particular user has been granted speical rights, then the ldb file "inherts" those same rights, and once again, all other users are either read only, or can't use the database.
So, to make a longer story short?
All users rights to that folder as a general rule need file create rights, and need file delete rights. And of course on your own personal computer this works, since for the most part you have full rights to quite much any folder and file(s) on your personal computer. So, you need to open up (relax) the security permissions on that shared folder - users need create file rights, and delete file rights.