是否可以直接在ODBC连接字符串中指定驱动程序dll? [英] Is it possible to specify the driver dll directly in the ODBC connection string?

查看:97
本文介绍了是否可以直接在ODBC连接字符串中指定驱动程序dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use pyodbc to connect to a SQL Server (MS SQL Server through FreeTDS) in a portable application; since it's supposed to be standalone, I would like to avoid having to explicitly install the driver on the system, just bringing the ODBC driver dll along the application.

此页面建议可以直接在连接字符串中指定驱动程序dll

This page suggests that it's possible to specify the driver dll directly in the connection string

  • SQLDriverConnect函数的szConnStrIn参数中指定DRIVER=参数.例如:

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

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

其中ospath是Adaptive Server Anywhere安装目录的操作系统子目录.

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

在Linux上通过pyodbc + libtdsodbc.so进行尝试,可以正常工作;但是,在Windows上尝试相同的方法(pyodbc + tdsodbc.dll)我总是得到

Trying it through pyodbc+libtdsodbc.so on Linux, it does work fine; however, trying the same on Windows (pyodbc+tdsodbc.dll) I always get

pyodbc.Error :("IM002","[IM002] [Microsoft] [ODBC驱动程序管理器]数据源名称未找到且未指定默认驱动程序(0)(SQLDriverConnect)")

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

(不过,我的libtdsodbc.so似乎很好,因为,如果我将其安装为常规"驱动程序并使用其名称进行引用,则说明可以正常连接)

(my libtdsodbc.so seems to be fine, though, since, if I install it as a "regular" driver and refer it with its name it connects fine)

检查 SQLDriverConnect的文档和相关页面,没有提到直接与dll路径一起使用的DRIVER=选项.

因此,Windows不支持直接驱动程序dll"连接吗?是否有其他选择(尤其是使用Python)绕过ODBC驱动程序管理器直接连接到驱动程序dll?

So, isn't "straight-to-driver-dll" connection not supported on Windows? Are there any alternatives, especially with Python, to connect straight to the driver dll, bypassing the ODBC driver manager?

推荐答案

现在可能无法解决此问题,在2.5年后,但是我最好的猜测是未注册的libtdsodbc.so或其他上的错字或权限错误SQLDriverConnect()调用中出现错误(您未提供,因此无法分析).

It's likely impossible to troubleshoot this now, 2.5 years later, but my best guess would be a typo or permissions error on the unregistered libtdsodbc.so, or some other error in your SQLDriverConnect() call (which you did not provide, so cannot be analyzed).

我认为您一定不能阅读SQLDriverConnect() 的文档要仔细或完整,因为它

I think you must not have read the documentation of SQLDriverConnect() carefully or completely, as it explicitly includes DRIVER in the EBNF of SQLDriverConnect() --

empty-string ::=attribute ::= attribute-keyword=attribute-value | DRIVER=[{]attribute-value[}]

-和.

请注意,尽管它确实建立了无DSN的连接,但它并不会绕过ODBC驱动程序管理器"(因此,它不会引用Windows上的odbc.ini注册表树,也不会引用Windows上的odbc.ini文件).其他操作系统).

Note that this does not "bypass the ODBC driver manager," though it does make a DSN-less connection (so does not refer to the odbc.ini Registry trees on Windows, nor the odbc.ini file(s) on other OS).

这篇关于是否可以直接在ODBC连接字符串中指定驱动程序dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆