简体   繁体   中英

New to ODBC in R (RStudio), and getting a failed to connect error?

Working through a tutorial to pull database data with:

install.packages('RODBC')
require(RODBC)

myNewDB=odbcConnect("QV Training")

And I get the error:

In odbcDriverConnect("DSN=QV Training")
Data source name not found and no default driver specified
In odbcDriverConnect("DSN=QV Training") : ODBC connection failed

Is 'QV Training' meant to be the name of a database that may no longer be present?
How does R know where to look for the database anyway?

Thank you!

In Windows (unsure of other OSes) you need to go into the ODBC Data Source Administrator, and add the data source. The ODBC Data Source Administrator is accessed via the 'Administrative Tools' section of Control Panel (in Windows 10 at least).

ODBC 数据源管理员面板创建新的数据源面板为 sql server 面板创建一个新的数据源

The connection command is then simply

conn <- odbcConnect("QV Training")
library(RODBC)
con <- odbcConnect("Oracle", uid="system", pwd="root", rows_at_time = 500)
sqlQuery(con, "select file_name,sum(bytes)/1024/1024 AS MB from dba_data_files group by file_name")
d <- sqlQuery(con, "select * from dba_data_files")
close(con)

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