簡體   English   中英

如何使用 R 從托管在 AWS ubuntu 服務器上的 Rstudio Connect 訪問托管在 Azure Windows VM 上的 SQL 服務器數據庫?

[英]How to access SQL Server database hosted on Azure Windows VM using R from Rstudio Connect hosted on AWS ubuntu server?

我無法從 RStudio 連接服務器訪問托管在 Azure Windows VM 上的 SQL 服務器數據庫。 SQL 服務器配置為允許遠程連接。 我嘗試了以下 R 代碼,但沒有成功。 我還查看了該論壇上的其他帖子。 但是,他們都沒有解決這種特定情況。

odbc.ini文件內容:

[dbname]
Driver = /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
Server = azure_wvm_name.corp.mycompany.com
ServerSPN = MSSQLSvc/azure_wvm_name.corp.mycompany.com:1433
Database = sqldb
Port = 1433
UID =  mycompany\rkahn
PWD = myPassword
Trusted_Connection = yes
Encrypt = yes
TrustServerCertificate = yes
Kerberos = Yes

te.net ip_address 1433 ,正如“ AlwaysLearning ”所建議的那樣有效。

有人可以讓我知道我的代碼中缺少什么嗎?

library(odbc)
library(DBI)

UserId <- 'mycompany\rkahn'
UserPassword <- 'myPassword'
dbname <- 'sqldb'

sqlsrvcon <- dbConnect(odbc(),
                 Driver = "ODBC Driver 18 for SQL Server",
                 Server = "azure_wvm_name.corp.mycompany.com",
                 Database = dbname,
                 UID = UserId,
                 PWD = UserPassword,
                 Port = 1433)

我收到此錯誤消息:錯誤:nanodbc/nanodbc.cpp:1021:00000:[Microsoft][SQL 服務器的 ODBC 驅動程序 18]登錄超時已過期[Microsoft][SQL 服務器的 ODBC 驅動程序 18]MAX_PROVS:連接字符串無效[87]。 [Microsoft][SQL 服務器的 ODBC 驅動程序 18]建立與 SQL 服務器的連接時出現與網絡相關或特定於實例的錯誤。

我能夠通過 ODBC DSN 連接到 SQL 服務器

ubuntu@ip-xxx-xx-xx-xx:~$ isql -v dsnName

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

但是當我嘗試使用 R 連接時

con <- DBI::dbConnect(odbc::odbc(), "dsnName")

我收到此錯誤:錯誤:nanodbc/nanodbc.cpp:1021:00000:[Microsoft][SQL 服務器的 ODBC 驅動程序 18]SSL 提供程序:[錯誤:1416F086:SSL 例程:tls_process_server_certificate:證書驗證失敗:自簽名證書] [ Microsoft][ODBC Driver 18 for SQL Server]客戶端無法建立連接

最后這對我有用:

library(odbc)
library(DBI)

UserId <- 'mycompany\rkahn'
UserPassword <- 'myPassword'
dbname <- 'sqldb'

sqlsrvcon <- dbConnect(odbc(),
                 Driver = "/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1",
                 Server = "azure_wvm_name.corp.mycompany.com",
                 Database = dbname,
                 UID = UserId,
                 PWD = UserPassword,
                 Encrypt="yes",
                 TrustServerCertificate="yes",
                 Port = 1433)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM