I’m trying to fetch data from MS SQL server in a shiny app. I’m using the odbc package version 1.2.2.
When I run the app locally I am able to fetch the data and everything is fine. But on the server I have the following error :
x
Listening on http://127.0.0.1:5823Warning in connection_release(conn@ptr) : There is a result object still in use.The connection will be automatically released when it is closedWarning: Error in : <SQL> 'select Parameter.name,ParamValue.value from Parameter inner join ParamValue on Parameter.id = ParamValue.parameterId where Parameter.name = 'airDensity'order by Parameter.name' nanodbc/nanodbc.cpp:1587: 42000: [FreeTDS][SQL Server]Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. 81: <Anonymous>The following is a short version of my app.
library(shiny)ui <- fluidPage( withMathJax(), tabsetPanel( tabPanel("Help Page", h2(HTML("<ul> <b>How to use the tool</b></ul>")) ), tabPanel("LCA", dashboardPage(skin = "green", dashboardHeader(title = "LCA Database"), dashboardSidebar( tags$a(href = "https://www.xxxxxxxxx.com/en-int", tags$img(src='SG_logo_neg_rgb.png', height = 70, width = 230)), tags$hr(), selectInput("t1","Select Parameter", choices = c("Param")), selectInput("t2","Select Parameter", choices = c("-")) ), dashboardBody( ) ) ) ))and the server :
library(shiny) library(odbc) library(dbplyr) server <- function(input, output, session){ main <- reactive({ con <- dbConnect(odbc(), Driver = "libtdsodbc.so", Server = "xxxxx.xxxxxx.xxxxx", Database = "LCA", UID = "LCA-User", PWD = "xxxxxxxxxxxxxx", encoding = "windows-1252", Port = 1433) on.exit(odbc::dbDisconnect(con)) squery = dbSendQuery(con,"select name from Parameter order by name",stringsAsFactors = FALSE) parameterNmaes = dbFetch(squery ) result= list(parameterNmaes = parameterNmaes) return(result) }) # updating the first dropdown observeEvent(main(),{ updateSelectInput(session, "t1", choices = main()$parameterNmaes) }) # second dropdown based on user selection subselect1 <- reactive({ con <- dbConnect(odbc(), Driver = "libtdsodbc.so", Server = "xxxx.xxxxx.xxxx", Database = "LCA", UID = "LCA-User", PWD = "xxxxxxxxxxxxxx", encoding = "windows-1252", Port = 1433) on.exit(odbc::dbDisconnect(con)) squery = dbSendQuery(con,paste0("select Parameter.name,ParamValue.value from Parameter inner join ParamValue on Parameter.id = ParamValue.parameterId where Parameter.name = '",input$t1,"'order by Parameter.name"),stringsAsFactors = FALSE) p = dbFetch(squery ) p1 = p %>% mutate(deserial = lapply(p[,2], mType))%>% mutate(numericValue = sapply(lapply(deserial, deserialize),`[`, "v")) res = sort(as.character(unique(p1$numericValue))) result= list(res = res, p1 = p1) return(result) }) observeEvent(subselect1(),{ updateSelectInput(session, "t2", choices = subselect1()$res) }) }Advertisement
Answer
You could try odbc::odbcListDrivers() , I my case I have :
odbc::odbcListDrivers() name attribute value1 PostgreSQL Description ODBC for PostgreSQL2 PostgreSQL Driver /usr/lib/psqlodbcw.so3 PostgreSQL Setup /usr/lib/libodbcpsqlS.so4 PostgreSQL Driver64 /usr/lib64/psqlodbcw.so5 PostgreSQL Setup64 /usr/lib64/libodbcpsqlS.so6 PostgreSQL FileUsage 17 MySQL Description ODBC for MySQL8 MySQL Driver /usr/lib/libmyodbc5.so9 MySQL Setup /usr/lib/libodbcmyS.so10 MySQL Driver64 /usr/lib64/libmyodbc5.so11 MySQL Setup64 /usr/lib64/libodbcmyS.so12 MySQL FileUsage 113 FreeTDS Description FreeTDS for MSSQL14 FreeTDS Driver /usr/lib64/libtdsodbc.so15 FreeTDS Setup /usr/lib64/libtdsS.so16 FreeTDS Driver64 /usr/lib64/libtdsodbc.so17 FreeTDS Setup64 /usr/lib64/libtdsS.so18 FreeTDS FileUsage 119 FreeTDS UsageCount 120 MSODBC Description Microsoft ODBC Driver 13 for SQL Server21 MSODBC Driver /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.122 MSODBC UsageCount So then setting driver = "MSODBC " should solve the issue !