title: Connecting to Microsoft SQL Server on ODBC using R in Ubuntu
body: <p>I was able to get it completely working on Windows 7, but I have to move it to a Linux server. I'm running Ubuntu 16.04.1 LTS 64-bit in a VM right now for testing before I replicate the process on the server.</p>
  
  <p>I'm pretty sure the issue is somewhere in my FreeTDS or DSN setup.
  <br><b>Should I stop wasting my time and just use Python? Or will I have this same issue with ODBC and unixODBC?</b></p>
  
  <p><b>Full R script:</b></p>
  
  <pre><code>library(RODBC)
  
  #saving from a .csv to dataframe df
  df &lt;- read.csv("./Documents/test.csv")
  
  #creating connection to db
  conn &lt;- odbcDriverConnect('myDSN')
  
  #writing
  sqlSave(conn, df, tablename = 'dbo.test0', append = F, rownames = F, verbose = TRUE, safer = true, fast = F)
  </code></pre>
  
  <p><b>R Console</b></p>
  
  <pre><code>&gt; conn &lt;- odbcDriverConnect('myDSN')
  </code></pre>
  
  <p>Returns error message:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Here's my ODBC and FreeTDS config:</p>
  
  <p><b>/etc/odbc.ini</b></p>
  
  <pre><code>[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
  </code></pre>
  
  <p><b>/etc/odbcinst.ini</b></p>
  
  <pre><code>[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
  </code></pre>
  
  <p><b>/freetds/freetds.conf</b></p>
  
  <pre><code>[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
  </code></pre>