我有一个Oracle db,我使用RODBC连接连接到oracle,如下所示:
library(RODBC)
new_sql<-c("select * from table")
tryCatch({
ch=odbcConnect("odbc_con",pwd = "!passwd!")
res<-sqlQuery(ch,new_sql)
},error = function(e) {
print(odbcGetErrMsg(ch))
})数据库镜像到mssql,我使用管理员工具创建了一个新的到mssql的odbc连接,名为new_odbc_con使用数据源(ODBC)。
当我更新代码时:
tryCatch({
ch=odbcConnect("odbc_con",pwd = "!password!")
res<-sqlQuery(ch,new_sql)
},error = function(e) {
print(odbcGetErrMsg(ch))
})我无法连接到sql服务器并执行sql。我做错了什么?
发布于 2014-04-13 22:09:26
万一它再次出现,这就是我为解决这个问题所做的。
odbc连接。ch=odbcConnect("odbc_con",pwd = "!password!")到ch=odbcConnect("odbc_con",uid="userid",pwd = "!password!")很有魅力。
发布于 2017-09-07 14:56:06
还提供Linux解决方案,在调用R中的dsn之前,需要编辑下面的3个配置文件
$ sudo nano /etc/odbc.ini
[salesdb]
Driver=FreeTDS
Trace=No
Server=xxx
Port=1433
Database=xxxx
TDS_Version=8.0
$ sudo nano /etc/freetds.conf
# A typical Microsoft server
[salesdb]
host = xxxx
port = 1433
tds version = 8.0
client charset = UTF-8
$ sudo nano /etc/odbcinst.ini
# Driver from the FreeTDS package
# Setup from the unixODBC package
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib64/libtdsodbc.so # this is the linux path, you can call odbcinst -q -d to see where the other drivers were installed in the system最后,您可以使用tsql或isql测试会话是否正确安装,或者下面的命令,
$ odbcinst -q -shttps://stackoverflow.com/questions/23045764
复制相似问题