python - 是否可以直接在ODBC连接字符串中指定驱动程序dll?

标签 python windows odbc pyodbc

我正在尝试使用 pyodbc 连接到可移植应用程序中的 SQL Server(通过 FreeTDS 的 MS SQL Server);因为它应该是独立的,所以我想避免在系统上显式安装驱动程序,只需将 ODBC 驱动程序 dll 与应用程序一起使用即可。

This page建议可以直接在连接字符串中指定驱动程序dll

  • Specify the DRIVER= parameter in the szConnStrIn argument to the SQLDriverConnect function. For example:

    szConnStrIn = "driver=ospath/dbodbc6.dll;dbf=c:\asademo.db"
    

    where ospath is the operating system subdirectory of your Adaptive Server Anywhere installation directory.

在 Linux 上通过 pyodbc+libtdsodbc.so 尝试,确实可以正常工作;然而,在 Windows 上尝试相同的操作 (pyodbc+tdsodbc.dll) 我总是得到

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

(我的 libtdsodbc.so 似乎没问题,因为,如果我将它安装为“常规”驱动程序并使用它的名称引用它,它连接正常)

正在检查 the documentation of SQLDriverConnect和相关页面没有提及直接与 dll 路径一起使用的 DRIVER= 选项。

那么,Windows 不支持“直接到驱动程序 dll”连接吗?是否有任何替代方法(尤其是使用 Python)绕过 ODBC 驱动程序管理器直接连接到驱动程序 dll?

最佳答案

the answer by TallTed提到,您链接的文档包含相当多的信息(但当时可能不存在),并且它也明确说明了 driver 参数的含义:

Description of the driver as returned by the SQLDrivers function. For example, Rdb or SQL Server.

由此可见,在 Windows 中指示那里的路径是无效的(至少使用默认的 ODBC 实现)。

一般情况下,似乎也无法在不注册的情况下使用 ODBC 驱动程序,这需要管理员权限。 This answer列出了一些选项。

关于python - 是否可以直接在ODBC连接字符串中指定驱动程序dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40263138/

相关文章:

python - 如何在python中向自定义dict子类添加类型注释?

python - 以矢量化方式切片 Pandas 字符串

使用包含带有 span 元素的文本时的 Python selenium 问题

r - 通过 RODBC 连接到 SQLite

python - 无法使用 selenium webdriver 单击网页中的链接

c++ - 为什么我的程序在启动前就崩溃了?

windows - "yarn resourcemanager"产生 "The system cannot find the batch label specified - resourcemanager"

c++ - 在 Windows 上的预处理器中检测带有符号的建筑物

c# - Odbc Paradox 驱动程序 WHERE 子句 日期

mysql - 在 visual studio 中使用 MySQL 并在运行时更改连接