我能够完全使用Windows 7,但我必须将其移至Linux服务器。我现在正在VM中运行Ubuntu 16.04.1 LTS 64位进行测试,然后再在服务器上复制进程。
我很确定问题出在我的FreeTDS或DSN设置中。
我应该不再浪费时间而只是使用Python吗?或者我对ODBC和unixODBC有同样的问题吗?
Full 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
答案 0 :(得分:1)
我有RODBC - &gt; FreeTDS - &gt; SQL Server在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
除了tds version = 8.0
之外,我的freetds.conf是相同的,并且我的服务器条目的名称与它在odbc.ini中的条目相同。
这个和文档应该有希望让你到那里。