Search code examples
rspotfire

Insert R DataFrame into SQL Server Table


I have been stuck on this for a couple days now...I cant find what the issue could be. I am using R in Spotfire. I am trying to insert the results of a dataframe into a sql server 2014 table. This is an example of what I am using:

install.packages("ODBC")
install.packages("DBI")


library(DBI)
library(odbc)

con <- dbConnect(odbc(),
             Driver = "SQL Server",
             Server = "ServerName",
             Database = "DatabaseName",
             UID = "UserName",
             PWD = "Password")
dbWriteTable(conn = con, 
         name = "SQlServerTableDestinationName", 
         value = Datatable)

I get this error:

TIBCO Enterprise Runtime for R returned an error: 'Error in .loadNamespaceImpl(package, path, keep.source, partial) : error executing useDynLib for dynamic library 'rlang' from package 'rlang' loaded from P:/TERR/x86_64-pc-windows-library/4.2 : Error in library.dynam(chname = chname, package = package, lib.loc = ... : Foreign binary rlang could not be loaded'.

Thank you!


Solution

  • Please follow the TIBCO community solution suggested here: https://community.tibco.com/wiki/tibcor-enterprise-runtime-r-fast-writeback-sql-server-2016

    In your case it would be something like below:

    dbcon <- RODBC::odbcDriverConnect(connection_string )
    RODBC::sqlSave(dbcon, dat =  dataf, "SQlServerTableDestinationName")
    

    Please let me know if it helps