Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server RODBC Connection

Tags:

r

rodbc

Does anyone have a connection string example for using RODBC and connecting to MS SQL Server 2005 or 2008.

Thank you.

like image 394
Brandon Avatar asked Apr 19 '11 17:04

Brandon


People also ask

How do you set up a Rodbc?

Click “Packages” à Install package(s)… from the RGui Toolbar. If you have not already selected a mirror for CRAN downloads, do so by selecting a mirror that will best serve your geographic location. Select “RODBC” from the package list. The RODBC package has been successfully installed.

What is Rodbc?

The RODBC package provides access to databases (including Microsoft Access and Microsoft SQL Server) through an ODBC interface. The primary functions are given below. Function. Description. odbcConnect(dsn, uid="", pwd="")


2 Answers

library(RODBC) dbhandle <- odbcDriverConnect('driver={SQL Server};server=mysqlhost;database=mydbname;trusted_connection=true') res <- sqlQuery(dbhandle, 'select * from information_schema.tables') 
like image 68
Henrico Avatar answered Oct 14 '22 07:10

Henrico


Taken from a posting to r-help:

 library(RODBC)
 channel <- odbcDriverConnect("driver=SQL Server;server=01wh155073")
 initdata<- sqlQuery(channel,paste("select * from  test_DB .. 
 test_vikrant"))
 dim(initdata)
 odbcClose(channel)
like image 22
IRTFM Avatar answered Oct 14 '22 09:10

IRTFM