3

I connected R with SQL Server (in Visual Studio 2017) the connection succeeded this is Setting.R

 settings <- as.environment(list())
   dbConnection1 <- 'Driver={SQL Server};Server= 
   (local);Database=SaVeITDB;Trusted_Connection=yes'

this is SqlQuery.sql also executing the below query succeeded

-- Place SQL query retrieving data for the R stored procedure here
select AOIName from AreaOFInterest a, ProjectsAOI p where p.AOIId = a.AOIId;

and this is Script.R when I executing it throw this function in df file

 source("Settings.R")
 library(RODBC)
 conn <- odbcDriverConnect(connection = dbConnection)
 df <- sqlQuery(conn,  iconv(paste(readLines('c:/users/comnet/source/repos/rproject3/rproject3/sqlquery.sql', encoding = 'UTF-8', warn = FALSE), collapse = '\n'), from = 'UTF-8', to = 'ASCII', sub = ''))
 View(df)

this df file (appears with lock icon)

function(x, df1, df2, ncp, log = FALSE) {
if (missing(ncp))
    .Call(C_df, x, df1, df2, log)
else .Call(C_dnf, x, df1, df2, ncp, log)}

enter image description here

Edit

It's executing correctly without any error after run Visual studio as admin

Husam Mohamed
  • 432
  • 1
  • 4
  • 15

0 Answers0