使 Python 在 Windows 上更快地访问 MS Access
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在程序启动时设置一次连接,然后在各处重复使用该连接。而不是在每次执行或提交后关闭它。
Try setting up your connection once on program startup and then reusing the connection everywhere. Rather than closing it after every Execute or Commit.
托尼的建议对我来说最有意义。但是,如果还不够,您还可以尝试更高版本的驱动程序,例如 这个适用于 Office 2007 文件(当然也包括旧版本)。即使您没有 Office,也可以下载并安装它。
安装完成后,尝试使用如下连接字符串:
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: