2016-12-29 72 views
2

我能夠在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 
+0

我不認爲這是R具體。從我從Linux連接到SQL Server已經有一段時間了,但請記住,在Python中也很難。 – duffn

+0

爲什麼不使用SQL Server的[Microsoft的ODBC Linux](https://msdn.microsoft.com/en-us/library/hh568451(v = sql.110).aspx)驅動程序?另請注意,您的ini文件使用了很多不同名稱的名稱 - myDSN,myDSN0和DSN0 –

回答

1

我有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 mydsntsql -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。

這和文檔應該有希望讓你在那裏。

+0

當[提供程序提供的ODBC驅動程序](https://)時,您不需要通過FreeTDS msdn.microsoft.com/en-us/library/hh568451(v=sql.110).aspx)可用。 –

+0

有沒有人測試FreeTDS針對Linux的MS ODBC?我很想看看哪個更快。 – blongworth

相關問題