我尝试的第一种方法有效。我首先在Windows上使用my_connection_name
定义了一个ODBC连接ODBC data source administrator
。然后,我使用以下代码:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc(),
dsn='my_connection_name',
UID = "firstname.lastname@company.com",
PWD = "mypassword")
这很好!
但是,当我尝试在dbConnect
函数中定义驱动程序,服务器和数据库名称时。它失败!
con <- DBI::dbConnect(odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = 'my_server_name',
Database = "my_database_name",
UID = "firstname.lastname@company.com",
PWD = "mypassword",
Trusted_Connection = "yes")
我遇到错误:
Error: nanodbc/nanodbc.cpp:950: 08S01: [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote host.
有趣的是,当我删除Trusted_Connection = "yes"
时。
con <- DBI::dbConnect(odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = 'my_server_name',
Database = "my_database_name",
UID = "firstname.lastname@company.com",
PWD = "mypassword")
我收到这样的错误消息:
错误:nanodbc / nanodbc.cpp:950:HY000:[Microsoft] [用于SQL Server的ODBC驱动程序13] [SQL Server]无法打开登录请求的服务器“ company.com”。登录失败。
当我之前定义ODBC连接时,我使用了相同的驱动程序,服务器和数据库名称。
我的身份验证选项为ActiveDirectoryPassword
。
有人知道发生了什么事吗?
答案 0 :(得分:0)
如果使用可信连接=是,则无需提供用户名和密码。您的服务帐户将用于连接到SQL Server。
con <- DBI::dbConnect(odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = 'my_server_name',
Database = "my_database_name",
Trusted_Connection = "yes")