首页 > 解决方案 > sql server 升级到 TLS 1.2 后将 R 连接到 SQL Server 时遇到问题

问题描述

我一直使用以下代码成功连接到 R 中的 sql server

dbhandle=odbcDriverConnect("Driver={SQL Server};Server=servername;Database=databasename;Trusted_Connection=Yes")

但是,sql server 升级为兼容 TLS 1.2 后出现以下错误

Warning messages:
1: In odbcDriverConnect("Driver={SQL Server};Server=MHPOPMMSS100;Database=REZNKWB01;Trusted_Connection=Yes") :
  [RODBC] ERROR: state 08001, code 18, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SSL Security error
2: In odbcDriverConnect("Driver={SQL Server};Server=MHPOPMMSS100;Database=REZNKWB01;Trusted_Connection=Yes") :
  [RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECCreateCredentials()).
3: In odbcDriverConnect("Driver={SQL Server};Server=MHPOPMMSS100;Database=REZNKWB01;Trusted_Connection=Yes") :
  ODBC connection failed

我从来不需要 uid,但我尝试输入用于直接连接到 sql server 的相同用户 ID,我尝试过 trustconnection=yes 和否,我尝试在服务器之后添加端口,基本上是我在网上阅读的任何内容我努力了。

我想知道是否有我遗漏的东西或者是否有人有意见。谢谢!

标签: rsql-serverrodbc

解决方案


library(RODBC)
dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;Server=Server_Name; Database=DB_Name;Uid=; Pwd=; trusted_connection=yes")
initdata <- sqlQuery(dbconnection,paste("select * from MyTable;"))
odbcClose(channel)

另外,请参阅下面的链接。

http://stackoverflow.com/questions/15420999/rodbc-odbcdriverconnect-connection-error

https://andersspur.wordpress.com/2013/11/26/connect-r-to-sql-server-2012-and-14/

最后,确保您的设置兼容 32 位或 64 位。在 SQL Server 中,执行以下操作:选择 @@Version

这将告诉您使用的是 32 位还是 64 位。确保您的 R Studio 与您正在运行的任何版本的 SQL Server 兼容。

Note that by holding down the Control key during the launch of RStudio you can cause the R version selection dialog to display at startup.

在此处输入图像描述


推荐阅读