简体   繁体   中英

Connecting R to an MS SQL database on a Mac using RODBC

I'm trying to connect to an MS SQL database from R (on a Mac) - after fiddling a lot with odbc.ini, odbcinst.ini, and installing freeTDS as described:

sudo port install freetds +mssql +odbc +universal

it now works on the Mac's command line level, but when trying to access it from R using the command:

con <- odbcConnect("myDSN", uid = "myID", pwd = "myPWD")

it just hangs and when forced to stop executing, I get 50+ of the following warnings:

In odbcDriverConnect("DSN=myDSN;UID=myID;PWD=myPWD") :
  [RODBC] ERROR: state IM002, code 1421220112, message [iODBC][Driver Manager]Data source 
name not found and no default driver specified. Driver could not be loaded

After having tried to make it work for about two days, I'm running out of suggestions. Can anybody help point me to what I am missing?

EDIT: It also works when running R on the virtual Windows machine. How do I get it to work on the Mac?

Did you first configure your MS SQL driver connection? If you have, then you should have a data source called "myDSN" in the OCBC Data Source dialog box.

Here is a great blog which gives step-by-step instructions and screen captures for what you need to do.

When you issue queries in R, R will try to talk to the ODBC data source called "myDSN". That data source knows what database you want (MS SQL) and also what the credentials (username/password) are needed to get access. This is the reason why you must configure the data source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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