我正在尝试通过api调用来提取数据另存为r dtaframe然后将r数据帧复制到MS Sql server。 api调用和与Sql服务器的连接完美无缺。但是,每当我尝试将r数据帧复制到sql server时,我都会收到错误消息。我已经尝试了我找到的所有选项,但没有任何效果。任何帮助表示赞赏。
library(RSocrata)
REData <- read.socrata("https://data.ny.gov/resource/i8hd-gucs.json", app_token = token, email = "email",
password = password,
stringsAsFactors = FALSE)
DBI::dbWriteTable(con, name = "tblDosActiveRealEstateSalesAgent",
data.frame(REData), field.types = NULL, row.names = FALSE, append = TRUE,
allow.keywords = FALSE)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"RODBC", "character", "data.frame"’
require(RODBC)
con <- odbcDriverConnect("Driver=ODBC Driver 13 for SQL Server;server=172.xx.xx.xx,1433;Database=ReportServer;uid=sa;Pwd=password")
会话信息:
R version 3.4.3 (2017-11-30)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RSQLite_2.1.0 jsonlite_1.5 RSocrata_1.7.4-7 odbc_1.1.5 RODBC_1.3-15
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 digest_0.6.13 mime_0.5 plyr_1.8.4 R6_2.2.2 DBI_0.8 httr_1.3.1 rlang_0.2.0 curl_3.2
[10] blob_1.1.1 tools_3.4.3 bit64_0.9-7 bit_1.1-12 hms_0.4.2 yaml_2.1.18 compiler_3.4.3 pkgconfig_2.0.1 memoise_1.1.0
答案 0 :(得分:0)
如果您由于试图将MS SQL与R和DBI一起使用而来到这里,这可能会有所帮助:
对我来说,问题是DBI的方法在对象标识符周围添加了引号。将QUOTED_IDENTIFIER设置为ON可解决此问题。
dbExecute(myConnection,“将quoted_identifier设置为开”)