本文介绍了无法从Shinyapps.io连接到Microsoft Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个Rshiny应用程序,该应用程序从Microsoft Azure中提取数据.当我在连接字符串中使用"SQL Server"驱动程序时,我的应用程序在本地运行,但是当我在应用程序Shinyapps.io上发布该应用程序时,该应用程序无法运行.根据此处的建议,在Shinyapps.io上发布时,一直试图使用"FreeTDS"驱动程序与Azure连接,但是我没有任何运气.

I built an Rshiny application that pulls data from Microsoft Azure. My application works locally when I use the 'SQL Server' driver in my connection string, but does not work when I publish the app on shinyapps.io.Based on a suggestion from here, I have been trying to use the 'FreeTDS' driver to connect with Azure when publishing on shinyapps.io but I am not having any luck.

这是我的连接字符串:

con <- dbConnect(odbc::odbc(),
                 Driver = "FreeTDS",
                 Server = "servername",
                 Database = "databasename",
                 Uid = "uid",
                 Pwd = "pwd",
                 Port = 1433,
                 TDS_Version = 9.0)

使用"FreeTDS"驱动程序时,我收到以下错误消息:

I receive the following error message when using the 'FreeTDS' driver:

Error in value[[3L]](cond) :
  nanodbc/nanodbc.cpp:950: 08001: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source

我尝试使用TDS_Version 7.0、7.2、7.4、9.0-均无效.谁能帮助我解码此错误消息?谢谢!

I have tried using TDS_Version 7.0, 7.2, 7.4, 9.0 - none have worked. Can anyone help me decode this error message? Thank you!

注意:我正在Windows 10上使用R 3.6.我已将Azure上的Shinyapps.io IP地址列入白名单,所以这不是问题.

Note: I am working with R 3.6 on Windows 10. I have whitelisted shinyapps.io IP addresses on Azure, so that is not the issue.

推荐答案

对于在本地Windows和Shinyapps.io上进行连接,这对我来说是有效的:

For connecting both on local Windows and Shinyapps.io, this has worked for me:

library(RODBC)

is_local<-Sys.getenv('SHINY_PORT')==""

dbConnector <- function(local=FALSE){
    if(local){dbConn <- odbcDriverConnect("Driver=ODBC Driver 13 for SQL Server;Server=xxx.database.windows.net,1433;Database=xxxxxxxxx;Uid=xxxx;Pwd=xxxxxxxxx;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30")
        } else {dbConn <- odbcDriverConnect("Driver=FreeTDS;TDS_Version=8.0;Server=xxxx.database.windows.net; Port=1433;Database=xxxxx;Uid=xxxxxx;Pwd=xxxxxxxxx;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30")}
}
dbConn <- dbConnector(is_local)

这篇关于无法从Shinyapps.io连接到Microsoft Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 17:12