Cannot connect to Microsoft Azure from shinyapps.io

て烟熏妆下的殇ゞ 提交于 2019-12-11 06:06:55

问题


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.

Here is my connection string:

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

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 

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!

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.


回答1:


The driver requires DSN and PWD to be specified only on the connection string, they cannot be specified in the DSN. http://www.freetds.org/userguide/odbcconnattr.htm

For more details, refer Similar GitHub issue, which addresses similar issue.

Hope this helps.




回答2:


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)


来源:https://stackoverflow.com/questions/56486557/cannot-connect-to-microsoft-azure-from-shinyapps-io

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