我正在尝试从 R 连接到在 Microsoft Azure 虚拟机上运行的 Microsoft SQL Server 数据库。
这是我的连接字符串
library(RODBC)
channel = odbcConnect(dsn="something.cloudapp.net",uid="myusername",pwd="mypassword");
但是,我不断收到此错误
Warning messages:
1: In odbcDriverConnect("DSN=servername.cloudapp.net,1433;UID=myusername;PWD=mypassword") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=servername.cloudapp.net,1433;UID=myusername;PWD=mypassword"):
ODBC connection failed
为什么我总是收到此错误?
最佳答案
尝试使用更灵活的 odbcDriverConnect
功能如下:
odbcDriverConnect('driver={SQL Server};Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;')
为了便于阅读,这里带有回车符:
odbcDriverConnect(
'driver={SQL Server};
Server=myServerAddress;
Database=myDataBase;
User Id=myUsername;
Password=myPassword;')
另请参阅:
关于sql-server - 无法从 R 连接到 azure vm 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32705095/