简体   繁体   English

尝试使用 RODBC 将 R 连接到 PostgreSQL 时出错

[英]Error when trying to connect R to PostgreSQL using RODBC

I am trying to connect to R using RODBC.我正在尝试使用 RODBC 连接到 R。 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注意我使用的是 Mac OSX

EDIT: The answer below is outdated, as some of the mentioned packages aren't available on CRAN any longer.编辑:下面的答案已经过时,因为某些提到的软件包不再在 CRAN 上可用。 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? 如何在 OSX 10.10.2 上将 R 与 PostgreSQL 连接?


For connection to PostgreSQL on Mac, you can use the package RpgSQL .要连接到 Mac 上的 PostgreSQL,您可以使用 package RpgSQL Be sure to read the installation notes , as your PostgreSQL installation has to be set up for using JDBC.请务必阅读安装说明,因为您的 PostgreSQL 安装必须设置为使用 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 ).如果您安装 PostgreSQL,则在安装过程结束时启动 Stack Builder(请参阅安装指南)。 Alternatively, you can use the Stack Builder (included in the postgreSQL installation) after installation to add extra components.或者,您可以在安装后使用 Stack Builder(包含在 postgreSQL 安装中)添加额外的组件。 Under Database drivers you should find postgresql JDBC.在数据库驱动程序下,您应该找到 postgresql JDBC。

The rdbi package mentioned in the comments, is removed from CRAN and afaik not maintained any more.评论中提到的rdbi package 已从 CRAN 中删除,afaik 不再维护。

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.如果你真的需要使用 ODBC,你需要一个 PostgreSQL 的驱动程序,并且必须知道你的计算机上的 ODBC 实现。 The driver Jim M. gave you is one option, another one is the drivers of Openlinksw or the "official" one on pgFoundry . Jim M. 给你的驱动程序是一种选择,另一种是Openlinksw的驱动程序或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. 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.对于最新版本的 OSX,您显然需要安装自己的 odbc 管理器。 Next to the one Eelke mentioned in the comments, you have the one from Apple as well here .在评论中提到的 Eelke 旁边,你也有来自 Apple In this manager, you can specify the driver location etc, and set up the connection to PostgreSQL through ODBC.在此管理器中,您可以指定驱动程序位置等,并通过 ODBC 设置与 PostgreSQL 的连接。 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 .阅读iODBC 的常见问题解答中的相关部分以及Mac 上 ODBC 上的部分总是很有趣。

On a sidenote: In R, You can check which DSNs can be found by using the command odbcDataSources() of the RODBC package.附带说明:在 R 中,您可以使用 RODBC package 的命令odbcDataSources()检查可以找到哪些 DSN。 If Postgresql is not mentioned in there, you know you have to look at your setup first.如果 Postgresql 没有在里面提到,你知道你必须先看看你的设置。

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.根据您要连接的数据库, Actual Technologies有适用于开源数据库(MySQL、PostgreSQL)、Oracle 以及 Microsoft Access 等的 Mac OSX 驱动程序,价格约为 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. ODBC 管理员中的设置很简单,无论您是想为机器上的所有用户(系统 DSN)还是为用户特定级别创建连接,因为有一个向导可以完成基本步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM