在ODBC上使用R连接到Microsoft SQL Server
我能够在Windows 7上完全使用它,但我必须将它移动到Linux服务器。我现在在虚拟机中运行Ubuntu 16.04.1 LTS 64位进行测试,然后在服务器上复制进程。在ODBC上使用R连接到Microsoft SQL Server
我很确定这个问题是在我的FreeTDS或DSN设置的某个地方。
我应该停止浪费时间,只使用Python吗?或者我会与ODBC和unixODBC有这个相同的问题?
,完全R脚本:
library(RODBC)
#saving from a .csv to dataframe df
df <- read.csv("./Documents/test.csv")
#creating connection to db
conn <- odbcDriverConnect('myDSN')
#writing
sqlSave(conn, df, tablename = 'dbo.test0', append = F, rownames = F, verbose = TRUE, safer = true, fast = F)
[R控制台
> conn <- odbcDriverConnect('myDSN')
返回错误信息:
Warning messages:
1: In odbcDriverConnect("myDSN") :
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified
2: In odbcDriverConnect("myDSN") : ODBC connection failed
这里是我的ODBC和freetds的配置:
/etc/odbc.ini
[myDSN]
APP = unixodbc
Description = master on DBNAME
Driver = TDSdriver
Server = SERVNAME
Database = DBNAME
Port = 1433
Username = UNAME
Password = PW
#Trace = No
#TraceFile = /var/log/freetds/freetds--odbc.log
/etc/odbcinst.ini
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
[myDSN0]
APP = unixodbc
Description = user on DBNAME
Driver = TDSdriver
Server = SERVNAME
Database = DBNAME
Port = 1433
Username = UNAME
Password = PW
#Trace = No
#TraceFile = /var/log/freetds/freetds--odbc.log
/freetds/freetds.conf
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[DSN0]
host = IPADDRESS
port = 1433
tds version = 7.2
client charset = UTF-8
我有RODBC - > FreeTDS - > SQ L服务器在linux Mint上工作。它是因为我已经配置好一会儿,但这里有一些(未经测试)建议:
有一些很好的安装注意事项在: http://www.saltycrane.com/blog/2011/09/notes-sqlalchemy-w-pyodbc-freetds-ubuntu/
,当然RTFM的: http://www.freetds.org/userguide/
灿您通过从命令行使用isql mydsn
或tsql -S mydsn
来缩小问题的范围?很确定这会告诉你,你的问题在FreeTDS设置中。
它看起来像你的ODBCINST.INI具有从矿山几个来进行比较:
[TDSDriver]
Description = TDS driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
我freetds.conf是除了tds version = 8.0
相同的,我的服务器条目的名称是一样的,因为它是在ODBC条目。 INI。
这和文档应该有希望让你在那里。
当[提供程序提供的ODBC驱动程序](https://)时,您不需要通过FreeTDS msdn.microsoft.com/en-us/library/hh568451(v=sql.110).aspx)可用。 –
有没有人测试FreeTDS针对Linux的MS ODBC?我很想看看哪个更快。 – blongworth
我不认为这是R具体。从我从Linux连接到SQL Server已经有一段时间了,但请记住,在Python中也很难。 – duffn
为什么不使用SQL Server的[Microsoft的ODBC Linux](https://msdn.microsoft.com/en-us/library/hh568451(v = sql.110).aspx)驱动程序?另请注意,您的ini文件使用了很多不同名称的名称 - myDSN,myDSN0和DSN0 –