这就是我如何让我的工作。请注意,您必须在 ODBC 数据源管理器中设置 ODBC DSN,然后您需要确保连接字符串中的驱动程序名称与您的 DSN 使用的完全匹配。就我而言,它是“SQL Server Native Client 11.0”。花括号似乎允许在驱动程序名称中使用空格。另外,我必须将trusted_connection
参数设置为“yes”而不是“true”。
instance_name <- "yourDsnName";
database_name <- "youDataBaseName";
connStr <- paste("Driver={SQL Server Native Client 11.0};Server=",instance_name, ";Database=",database_name,";Trusted_Connection=yes;",sep="");
# Set other variables used to define the compute context
sqlWait = TRUE;
sqlConsoleOutput = FALSE;
sqlShareDir <- paste("C:\\RShared\\",Sys.getenv("USERNAME"),sep="")
# Create and set the compute context to Dev SQL Server
sqlCC <- RxInSqlServer(connectionString = connStr, shareDir = sqlShareDir,
wait = sqlWait, consoleOutput = sqlConsoleOutput,
traceEnabled=TRUE,traceLevel=7)
rxSetComputeContext(sqlCC)
rxGetVarInfo(RxSqlServerData(sqlQuery = "select 1 as test",connectionString = connStr, colClasses = c(test = "integer"), rowsPerRead=500))