0
我知道有很多類似的問題關於連接到RODBC閃亮。但是,他們的解決方案都不適合我。RODBC無法連接閃亮 - odbcValidChannel(通道)不是TRUE
我已經連接到我的SQL服務器本地沒有問題,但發佈的閃亮的應用程序無法連接。
當本地運行的應用程序,我使用:
myData <- reactive({
##connect to database
myServer <- "***"
myUser <- "***"
myPassword <- "**"
myDatabase <- "lto"
myDriver <- "ODBC Driver 13 for SQL Server"
connectionString <- paste0(
"Driver=", myDriver,
";Server=", myServer,
";Database=", myDatabase,
";Uid=", myUser,
";Pwd=", myPassword)
conn <- odbcDriverConnect(connectionString)
dbhandle <- odbcDriverConnect(connectionString)
query='SELECT [menu_item_id]
,[primary_brand_id],[Q1],[Q2],[Q3]
,[Q4],[Q5],[Q6],[Q7],[brand],[brand_parent]
,[menu_item_name],[course_category],[day_part]
,[description],[display_name],[display_with_brand]
,[meal_part],[product_category],[reported]
,[month],[year],[year_month],[period],[respondent_id]
,[generation],[gender],[ethnicity],[income]
,[eater_archetype],[survey_type]
FROM [dbo].[vw_menu_item_responses]
WHERE [month]=?'
#month<-3
#store results
res <- sqlExecute(channel = dbhandle,
query = query,
data = list(input$month),
fetch = TRUE,
stringsAsFactors = FALSE)
#close the connection
odbcClose(dbhandle)
#return results
res
})
output$table<- renderDataTable({
d<-myData()
head(d)
})
當試圖發佈應用程序,我使用:
myData <- reactive({
##connect to database
myServer <- "***"
myUser <- "***"
myPassword <- "**"
myDatabase <- "lto"
myDriver <- "FreeTDS;TDS_Version=9.0"
connectionString <- paste0(
"Driver=", myDriver,
";Server=", myServer,
";Database=", myDatabase,
";Uid=", myUser,
";Pwd=", myPassword)
conn <- odbcDriverConnect(connectionString)
dbhandle <- odbcDriverConnect(connectionString)
#build query
#query = "SELECT * FROM [my_db].[dbo].[my_table] where [CATEGORY] = '1070'"
#query = "SELECT * FROM [my_db].[dbo].[my_table] where [CATEGORY] = ?"
query='SELECT [menu_item_id]
,[primary_brand_id],[Q1],[Q2],[Q3]
,[Q4],[Q5],[Q6],[Q7],[brand],[brand_parent]
,[menu_item_name],[course_category],[day_part]
,[description],[display_name],[display_with_brand]
,[meal_part],[product_category],[reported]
,[month],[year],[year_month],[period],[respondent_id]
,[generation],[gender],[ethnicity],[income]
,[eater_archetype],[survey_type]
FROM [dbo].[vw_menu_item_responses]
WHERE [month]=?'
#month<-3
#store results
res <- sqlExecute(channel = dbhandle,
query = query,
data = list(input$month),
fetch = TRUE,
stringsAsFactors = FALSE)
#close the connection
odbcClose(dbhandle)
#return results
res
})
注意我也曾嘗試不同的TDS版本(7.0,8.0)。此外,問題不在於我的輸入$月變量,因爲我試圖將其設置爲常量,它仍然無法正常工作。
歡迎任何建議。請幫忙。
也明顯我的用戶ID,密碼和服務器實際上不是星號,但信息保密,我不想分享:)