Search code examples
ribm-cloudrstudiodashdb

RODBC connection to dashDB using R studio


When trying to set up a connection to dashDB from the rstudio ide on DSX I get this error:

[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified

This is after filling out this

dsn_driver <- "{IBM DB2 ODBC Driver}"
dsn_database <- "BLUDB" # e.g. "BLUDB"
dsn_hostname <- "<Enter Hostname>" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
dsn_port <- "50000" # e.g. "50000"
dsn_protocol <- "TCPIP" # i.e. "TCPIP"
dsn_uid <- "<Enter UserID>" # e.g. "dash104434"
dsn_pwd <- "<Enter Password>" # e.g. "7dBZ39xN6$o0JiX!m"

conn_path <- paste("DRIVER=",dsn_driver,
";DATABASE=",dsn_database,
";HOSTNAME=",dsn_hostname,
";PORT=",dsn_port,
";PROTOCOL=",dsn_protocol,
";UID=",dsn_uid,
";PWD=",dsn_pwd,sep="")
conn <- odbcDriverConnect(conn_path)
conn

So this code does not work for me. Is there anything I am missing here? I imported the RODBC library.


Solution

  • You can use the odbcConnect() and provide the dsn string as the only required parameter. On DSX, IBM DB2 ODBC DRIVER is initialized with the name BLUDB (so dsn_driver <- 'BLUDB'). Here is the working example:

    dsn_driver <- "BLUDB"
    dsn_database <- "BLUDB" # e.g. "BLUDB"
    dsn_hostname <- "<Enter Hostname>" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
    dsn_port <- "50000" # e.g. "50000"
    dsn_protocol <- "TCPIP" # i.e. "TCPIP"
    dsn_uid <- "<Enter UserID>" # e.g. "dash104434"
    dsn_pwd <- "<Enter Password>" # e.g. "7dBZ39xN6$o0JiX!m"
    
    conn_path <- paste(dsn_driver,
                       ";DATABASE=",dsn_database,
                       ";HOSTNAME=",dsn_hostname,
                       ";PORT=",dsn_port,
                       ";PROTOCOL=",dsn_protocol,
                       ";UID=",dsn_uid,
                       ";PWD=",dsn_pwd,sep="")
    conn <- odbcConnect(conn_path)
    conn