在Ubuntu上使用RODBC写入Microsoft SQL Server时出错

时间:2015-08-19 23:29:13

标签: sql-server ubuntu rodbc

我正在使用RODBC在Ubuntu环境中使用连接到Microsoft SQL数据库。我没有使用odbcConnect(建议我理解)连接到服务器/实例,而是编写了一个自定义连接字符串,并传递给odbcDriverConnect

con <- odbcDriverConnect(paste0("driver=", driver,";server=", host,";database=", dbname,";uid=", user, ";pwd=", password)) 

命令:

datatable <- sqlQuery(con, proccall) 

其中proccall包含数据库中的存储过程名称,就像魅力一样。当我尝试从sqlSave的文档重现以下示例时,使用相同的con,我收到以下错误:

sqlSave(con, USArrests, rownames = "state", addPK=TRUE)

Error in sqlSave(con, USArrests, rownames = "state", addPK = TRUE) : 
  42000 102 [FreeTDS][SQL Server]Incorrect syntax near 'USArrests'.
[RODBC] ERROR: Could not SQLExecDirect 'CREATE TABLE "USArrests"  ("state" varchar(255) NOT NULL PRIMARY KEY, "Murder" float, "Assault" int, "UrbanPop" int, "Rape" float)'

尝试同时测试写mtcars失败:

sqlSave(con, mtcars, rownames = TRUE, colnames = FALSE) 

Error in sqlSave(con, mtcars, rownames = TRUE, colnames = FALSE) : 
  42000 102 [FreeTDS][SQL Server]Incorrect syntax near 'mtcars'.
[RODBC] ERROR: Could not SQLExecDirect 'CREATE TABLE "mtcars"  ("rownames"  varchar(255), "mpg" float, "cyl" float, "disp" float, "hp" float, "drat" float, "wt" float, "qsec" float, "vs" float, "am" float, "gear" float, "carb" float)

我已经阅读过这些文档了,我一点也不清楚这里发生了什么。有什么想法吗?

0 个答案:

没有答案