我能夠在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
我不認爲這是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 –