为什么 macports pyodbc 在 MacOSX (Snow Leopard) 上找不到数据源名称或驱动程序?

发布于 2024-11-14 17:14:02 字数 1000 浏览 3 评论 0原文

我已经在 Snow Leopard 上安装了 py27-odbc 的 mac ports 包。由于 OSX 不再提供 ODBC 管理器应用程序,因此我安装了 OpenLink ODBC 管理器。安装后,我为远程数据库创建了 DSN,并使用 iodbctest 实用程序验证配置是否有效。然后,我尝试使用 pyodbc: 连接到数据库

import pyodbc
cnxn = pyodbc.connect('DSN=my-dsn-name;UID=joe;PWD=secret')

,并收到以下可爱的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name
not found, and no default driver specified (0) (SQLDriverConnectW)')

Why can't pyodbc find the ODBC drivers and/or my DSNconfigurations?

已更新(因为我还无法回答自己的问题)

看起来好像系统将 ODBC 配置数据存储在 /Library/ODBC 中,但 Mac Ports 将配置存储在 /opt/local/etc 中。这解释了为什么 iodbctest 可以工作,但 pyodbc 会阻塞。最干净的修复似乎只是从 Mac Ports 位置到系统位置的符号链接,这样一组通用的配置文件将适用于任何工具,无论它在哪里查找此信息:

sudo ln -s /Library/ODBC/odbc.ini /opt/local/etc/odbc.ini
sudo ln -s /Library/ODBC/odbcinst.ini /opt/local/etc/odbcinst.ini

I've installed the mac ports package for py27-odbc on Snow Leopard. Since OSX no longer supplies the ODBC Administrator application, I've installed the OpenLink ODBC manager. After installing, I created a DSN for my remote database, and verified that the configuration works using the iodbctest utility. I then attempt to connect to the database using pyodbc:

import pyodbc
cnxn = pyodbc.connect('DSN=my-dsn-name;UID=joe;PWD=secret')

and I get the following lovely error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name
not found, and no default driver specified (0) (SQLDriverConnectW)')

Why can't pyodbc find the ODBC drivers and/or my DSN configurations?

Updated (since I can't answer my own question yet)

It appears as if the system stores ODBC configuration data in /Library/ODBC, but the Mac Ports stores configuration in /opt/local/etc. This explains why iodbctest works, but the pyodbc chokes. The cleanest fix seems to be simply symlinking from the Mac Ports location to the system location, so that a common set of configuration files will work for any tool, regardless of where it's looking for this information:

sudo ln -s /Library/ODBC/odbc.ini /opt/local/etc/odbc.ini
sudo ln -s /Library/ODBC/odbcinst.ini /opt/local/etc/odbcinst.ini

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文