尝试使用 RODBC 将 R 连接到 PostgreSQL 时出错
我正在尝试使用 RODBC 连接到 R。但是,当我运行时,
ch <- odbcConnect("rails_dev", uid="skline", pwd="d0gsleep")
我收到此错误:
In odbcDriverConnect("DSN=rails_dev;UID=skline;PWD=d0gsleep") :
[RODBC] ERROR: state IM002, code 0, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded
有什么想法吗?我对此很陌生,不知道下一步该做什么......提前非常感谢!
注意我使用的是 Mac OSX
I am trying to connect to R using RODBC. However, when I run
ch <- odbcConnect("rails_dev", uid="skline", pwd="d0gsleep")
I get this error:
In odbcDriverConnect("DSN=rails_dev;UID=skline;PWD=d0gsleep") :
[RODBC] ERROR: state IM002, code 0, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded
Any thoughts? I am new to this and at a loss for what to do next... thank you so much in advance!'
Note I am using Mac OSX
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:下面的答案已经过时,因为其中提到的一些软件包在 CRAN 上不再可用。我把它留在这里供参考。
更多最新信息可以在以下问题中找到:
如何在 OSX 10.10.2 上将 R 与 PostgreSQL 连接?
要在 Mac 上连接 PostgreSQL,您可以使用包
RpgSQL
。请务必阅读安装说明,因为您的 PostgreSQL 安装必须设置为使用 JDBC。这是迄今为止最简单的方法。如果您安装 PostgreSQL,则需要在安装过程结束时启动 Stack Builder(请参阅 安装指南)。或者,您可以在安装后使用 Stack Builder(包含在 postgreSQL 安装中)来添加额外的组件。在数据库驱动程序下,您应该找到 postgresql JDBC。评论中提到的 rdbi 包已从 CRAN 中删除,并且不再维护。
如果您确实需要使用 ODBC,则需要 PostgreSQL 的驱动程序,并且计算机上的 ODBC 实现必须知道该驱动程序。 Jim M. 给您的驱动程序是一种选择,另一种是 Openlinksw 的驱动程序或pgFoundry 上的“官方”。通常,您应该能够像下载 JDBC 驱动程序一样从 Stack Builder 下载 ODBC 驱动程序:在数据库驱动程序标题下,您还有一个 postgresql ODBC。
对于最新版本的 OSX,您显然需要安装自己的 odbc 管理器。除了 Eelke 在评论中提到的那个之外,您还可以在此处找到来自 Apple 的那个。在此管理器中,您可以指定驱动程序位置等,并通过 ODBC 设置与 PostgreSQL 的连接。如何执行此操作取决于您使用的管理器,并且在帮助文件中进行了说明。阅读 iODBC 常见问题解答 中的相关部分总是很有趣有关 Mac 上的 ODBC 的部分。
旁注:在 R 中,您可以使用 RODBC 包的命令 odbcDataSources() 来检查可以找到哪些 DSN。如果其中没有提到 Postgresql,那么您就知道必须首先查看您的设置。
EDIT: The answer below is outdated, as some of the mentioned packages aren't available on CRAN any longer. I leave it here for reference.
More recent info can be found in the following question:
How to connect R with PostgreSQL on OSX 10.10.2?
For connection to PostgreSQL on Mac, you can use the package
RpgSQL
. Be sure to read the installation notes, as your PostgreSQL installation has to be set up for using JDBC. This is by far the easiest way. If you install PostgreSQL, you fire up the Stack Builder at the end of the installation process to do so (see the installation guide). Alternatively, you can use the Stack Builder (included in the postgreSQL installation) after installation to add extra components. Under Database drivers you should find postgresql JDBC.The
rdbi
package mentioned in the comments, is removed from CRAN and afaik not maintained any more.If you really need to use ODBC, you need a driver for PostgreSQL, and it has to be known to the ODBC implementation on your computer. The driver Jim M. gave you is one option, another one is the drivers of Openlinksw or the "official" one on pgFoundry. Normally, you should be able to download an ODBC driver from Stack Builder like you do for a JDBC driver : under the heading database drivers you have a postgresql ODBC as well.
For the newest versions of OSX, you need to install your own odbc manager apparently. Next to the one Eelke mentioned in the comments, you have the one from Apple as well here. In this manager, you can specify the driver location etc, and set up the connection to PostgreSQL through ODBC. How to do this, is dependent on the manager you use and is explained in the help files. It's always interesting to read the relevant section in the FAQ of iODBC and the sections on ODBC on Mac.
On a sidenote : In R, You can check which DSNs can be found by using the command
odbcDataSources()
of the RODBC package. If Postgresql is not mentioned in there, you know you have to look at your setup first.根据您要连接的数据库,Actual Technologies 提供适用于 Mac OSX 的开源数据库驱动程序(MySQL、 PostgreSQL)、Oracle、以及 Microsoft Access 等,价格约为 35 美元。无论您是要为计算机上的所有用户(系统 DSN)还是为特定于用户的级别创建连接,ODBC 管理员中的设置都很简单,因为有一个向导将逐步完成基本步骤。
Depending on the database you want to connect to, Actual Technologies has drivers for Mac OSX for open source databases (MySQL, PostgreSQL), Oracle, as well as Microsoft Access, etc, and costs about $35. Setup in ODBC administrator is straightforward whether you want to create a connection for all users on the machine (System DSN) or for user-specific level as there is a wizard that will walk through basic steps.