使 Python 在 Windows 上更快地访问 MS Access

发布于 2024-10-08 00:50:22 字数 426 浏览 0 评论 0原文

我在 Windows Server 2003 上,并使用 pyodbc 2.1.5 从 python 2.5.4 脚本访问本地存储的 MS Access 2000 MDB。

这种方式数据库访问非常慢(我在快速机器上,所有其他数据库操作都正常),我想知道是否有更好的方法从python访问MDB?也许有更好的 odbc 驱动程序?

这是我使用的示例脚本:

import pyodbc
cstring = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=t:\data.mdb'
conn = pyodbc.connect(cstring)
cursor = conn.cursor()
sql="UPDATE ..."
cursor.execute(sql)
conn.commit()
conn.close()

I am on a windows server 2003 and accessing a locally stored MS Access 2000 MDB from python 2.5.4 scripts using pyodbc 2.1.5.

The db access is very slow this way (I am on fast machine and all other db operations are normal) and I wonder if there is a better way to access the MDB from python? Maybe a better odbc driver?

This is an example script like I use:

import pyodbc
cstring = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=t:\data.mdb'
conn = pyodbc.connect(cstring)
cursor = conn.cursor()
sql="UPDATE ..."
cursor.execute(sql)
conn.commit()
conn.close()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

去了角落 2024-10-15 00:50:22

尝试在程序启动时设置一次连接,然后在各处重复使用该连接。而不是在每次执行或提交后关闭它。

Try setting up your connection once on program startup and then reusing the connection everywhere. Rather than closing it after every Execute or Commit.

爱的故事 2024-10-15 00:50:22

托尼的建议对我来说最有意义。但是,如果还不够,您还可以尝试更高版本的驱动程序,例如 这个适用于 Office 2007 文件(当然也包括旧版本)。即使您没有 Office,也可以下载并安装它。

安装完成后,尝试使用如下连接字符串:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\data.mdb;

Tony's suggestion makes the most sense to me. However, if it's not enough, you could also try a later version of the driver, such as this one that works with Office 2007 files (as well as older versions, of course). You can download and install it even if you don't have Office.

Once you have it installed, try a connection string like this:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\data.mdb;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文