Why can I not use dbWriteTable for SQL Server?

痞子三分冷 提交于 2021-02-08 10:40:45

问题


Does anyone know if something would have changed to break it? or am I missing something?

 data <- data.frame(x = rnorm(10), y = rnorm(10))

 cxn <- DBI::dbConnect(odbc::odbc(),
                      driver = 'ODBC Driver 17 for SQL Server',
                      server = dbServer,
                      database = dbName,
                      trusted_connection = 'yes',
                      port = port)

 DBI::dbWriteTable(cxn, tblName, data, append = T)

I'm getting the following error:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"Microsoft SQL Server", "character", "list"’

Here's my session Info:

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] 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] DBI_1.0.0         magrittr_1.5      lubridate_1.7.4   data.table_1.12.2
 [5] sloop_1.0.1       forcats_0.4.0     stringr_1.4.0     dplyr_0.8.3      
 [9] purrr_0.3.2       readr_1.3.1       tidyr_0.8.3       tibble_2.1.3     
[13] ggplot2_3.1.1     tidyverse_1.2.1   vctrs_0.2.0       devtools_2.0.2   
[17] usethis_1.5.1     conflicted_1.0.4 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        lattice_0.20-38   prettyunits_1.0.2 ps_1.3.0         
 [5] assertthat_0.2.1  zeallot_0.1.0     rprojroot_1.3-2   digest_0.6.20    
 [9] R6_2.4.0          cellranger_1.1.0  plyr_1.8.4        odbc_1.1.6       
[13] backports_1.1.4   httr_1.4.0        pillar_1.4.2      rlang_0.4.0      
[17] lazyeval_0.2.2    readxl_1.3.1      rstudioapi_0.10   callr_3.2.0      
[21] blob_1.1.1        desc_1.2.0        bit_1.1-14        munsell_0.5.0    
[25] broom_0.5.2       compiler_3.6.2    modelr_0.1.4      pkgconfig_2.0.2  
[29] pkgbuild_1.0.3    tidyselect_0.2.5  audio_0.1-6       crayon_1.3.4     
[33] withr_2.1.2       grid_3.6.2        nlme_3.1-142      jsonlite_1.6     
[37] gtable_0.3.0      scales_1.0.0      cli_1.1.0         stringi_1.4.3    
[41] fs_1.3.1          remotes_2.0.4     testthat_2.1.1    xml2_1.2.0       
[45] generics_0.0.2    tools_3.6.2       bit64_0.9-7       glue_1.3.1       
[49] hms_0.4.2         processx_3.3.1    pkgload_1.0.2     colorspace_1.4-1 
[53] sessioninfo_1.1.1 rvest_0.3.3       memoise_1.1.0     beepr_1.3        
[57] haven_2.1.0

回答1:


Recently I had similar issue.

Problem description: MS Server data base with scheme. The task is to save an R data.frame object to a predefined data base table without dropping it.

Problems I faced:

  • Some packages functions does not support schemes or require github development version installation
  • You can save data.frame only after drop (delete table) operation (I needed just "clear table" operation)

How I solved the issue

  • Using simple RODBC::sqlQuery, writing a data.frame row by row.
  • The solution (couple of functions) is available here or here


来源:https://stackoverflow.com/questions/61620287/why-can-i-not-use-dbwritetable-for-sql-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!