RODBC odbcDriverConnect() Connection Error

first argument is not an open rodbc channel
odbcdriverconnect r access
in odbcdriverconnect con rodbc error state im002 code 0
rodbc vs odbc
rodbc connect to sql server
rodbc connection failed
odbcdriverconnect package
rodbc close connection

I'm trying to use

odbcDriverConnect('driver={SQL Server};server=servername\instancename,port;database=testing;username=abc;password=123456') 

to connect remote database server (sql server 2008). But I got

[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.

error. Any idea?

I can use

odbcDriverConnect('driver={SQL Server};server=localhost;database=testing;trusted_connection=true') 

to connect my local database server (sql server 2008).

The correct syntax should be:

odbcDriverConnect('driver={SQL Server};server=servername\\instancename,port;database=testing;uid=abc;pwd=123456')

If you use Windows Authentication method:

odbcDriverConnect('driver={SQL Server};server=servername\\\\instancename,port;database=testing;trusted_connection=true')

Slash seems like an escape character, escaping slash works.

Connecting To A SQL Server, I am trying to connect to MS-SQL using the below code. You either need to load it with a library(RODBC) beforehand or use RODBC::odbcDriverConnect at the call. Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver library(DBI) library(odbc) conn <- dbConnect(odbc(), Driver = "SQL� odbcConnect establishes a connection to the specified DSN, and odbcDriverConnect allows a more flexible specification via a connection string. odbcConnect uses the connection string "DSN=dsn;UID=uid;PWD=pwd", omitting the last two components if they are empty. See the examples for other uses of connection strings.

For the Microsoft ODBC Driver 11 for SQL Server on Linux with RODBC version 1.3-7 in R version 3.0.1 none of the above answers worked. What did work however was the following:

dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;
                Server=; Database=MyDBName; 
                Uid=MyName; Pwd=XXXX")

(put in the relevant IP address, database name etc.).

In case of a trusted connection:

dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;
                Server=; Database=MyDBName; 
                Uid=MyName; Pwd=XXXX; trusted_connection=yes")

trusted_connection will only listen to "yes" or "no" and not to "true" and "false"

odbcConnect function, odbcDriverConnect(connection = "", case, believeNRows = TRUE, colQuote, tabQuote RODBC connection object returned by odbcConnect . A non- negative integer which is used as handle if no error occurred, -1 otherwise. re- connection odbcCloseAll() channel <- odbcReConnect(channel) # must re- assign as the� RODBC can use a DSN to connect to a database; the RODBC odbcConnect() function accepts a DNS name as an argument. We can, however, specify everything, including the ODBCdriver, right in the function call and do away with the DSN entirely. Such a connection is sometimes called a “DSN-less connection”.

1.Connet to MySQL

a)if Mysql is installed in your system, if not install it.

b)download the RMySQL IN R


drv = dbDriver("MySQL 5.0.1")

make sure MySQL version is correct.

con = dbConnect(drv,host="localhost",dbname="test",user="root",pass="root")

use local host or use the server i.e ip address

use the required database name, user name and password

album = dbGetQuery(con,statement="select * from table")

run required query


2.Another way to connect database

a)first install any database like MySQL,Oracle,SQL Server

b)install the ODBC connector for database


channel <- odbcConnect("test", uid="ripley", pwd="secret")

test is the connection name of odbc conector which user has to set manualy

user can find this in Administrator tool

res <- sqlFetch(ch, "table name")

A table can be retrieved as a data frame

res<-sqlQuery(channel, paste("select query"))

part of the with condition one table can be retrieved as a data frame

sqlSave(channel, dataframe)

to save a dataframe to the database(dont use "res<-" something like this)

like user can use

sqlCopy() sqlDrop()



always close the connection

Unable to connect to Microsoft SQL server from RStudio, Installed RODBC package;; Created ODBC DSN pointing to the SQL server I need to read data from. I can successfully connect to the server and read data through� connection character string. See your ODBC documentation for the format. further arguments to be passed to odbcDriverConnect. case Controls case changes for different DBMS engines. See ‘Details’. channel RODBC connection object returned by odbcConnect. believeNRows logical. Is the number of rows returned by the ODBC connection believable?

Looks like you are trying to connect to the SQL Server. This code snippet should work, it worked for me:


connection <- DBI::dbConnect(odbc::odbc(), Driver = "SQL Server", Server = "Your Server Name", Database = "Your Database Name", UID = "Your Database Name", UID = "Your Server Login", PWD = "Your Server Password", Port = 1433)

Reference: Connecting MS SQL Server via R

[PDF] rodbc, A connection to a specific database is called a Data Source Name or DSN More flexibility is available via function odbcDriverConnect, which works with RODBC allows primary keys to be set as part of the sqlSave() function when it There are at least two known problems with reading columns that do not have a format. Can't connect to SQL database using RODBC through Rstudio, but can using R in Hello,I've been trying to establish an odbc connection to one of our databses. I've got the odbc.ini and odbcinst.ini setup properly. I've tried to open a connection in R through shell and it works

[PDF] RODBC, The otheres return 1 on success and -1 on failure, indicating that a message is waiting to be retrieved RODBC connection object as returned by odbcConnect. odbcConnect establishes a connection to the specified DSN, and odbcDriverConnect allows a Otherwise a character string or invisible(). RODBC-package: ODBC Database Connectivity: odbcSetAutoCommit: ODBC Set Auto-Commit Mode: sqlTables: List Tables on an ODBC Connection: sqlSave: Write a Data Frame to a Table in an ODBC Database: odbcConnect: ODBC Open Connections: setSqlTypeInfo: Specify or Query a Mapping of R Types to DBMS Types: sqlColumns: Query Column Structure in ODBC

Connect Sql server from R Studio / RTVS failed, This works for me. library(RODBC) dbconnection <- odbcDriverConnect("Driver= ODBC Driver 11 for SQL Server;Server=Your_Server_Name\\� Dear All, I am really new to R. I have just started using it last week. I am trying to connect to MS-SQL using the below code. I am going through the Programming in R course from Edx. Below is the link for it. I have found the code to connect to a server using the below code only. Remember the server details, all are dummy here( as I can't share the original). I have also installed the RODBC

SQL Server Database connections in R, I think this is a common problem for my NHS colleagues when learning R and probably in to R using RODBC and using dplyr 's 'DBI-compliant' database connections. string RODBC_connection <- odbcDriverConnect(paste('driver={ SQL dbFetch(). You may not need to write a custom query for everyday use, but you� 1: In odbcDriverConnect(dsn) : [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 2: In odbcDriverConnect(dsn) : ODBC connection failed sessionInfo() R version 3.4.3 (2017-11-30) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows >= 8 x64 (build 9200)

  • Where's the explanation for putting a negative remark on that?