title: How to connect to Teradata Database using R + DBI +ODBC with osx (and windows VM)
body: <p>I work on a Mac, but also have a windows VM.</p>
  
  <p>I am trying to connect to a Teradata Database on both my Mac and Windows VM using R with the DBI library (so I can use dbplyr). Everything is working great on my Windows VM (see my previous question: <a href="https://stackoverflow.com/questions/54337267/connect-to-teradata-database-using-r-dbi-library-odbc">Connect to Teradata Database using R + DBI library + ODBC</a>).</p>
  
  <p>Again I suspect a driver issue, but I am not sure. I'm sure I had this working last week, but I can't remember. I know I have updated my Mac.</p>
  
  <hr>
  
  <p>Background:
  First here's my ODBC info if I look it the ODBC Administrator:</p>
  
  <ul>
  <li>Name = name_name</li>
  <li>Driver = Teradata</li>
  <li>Name or IP address = address.here.ok</li>
  <li>Mechanism = ldap</li>
  <li>Username = my_username</li>
  </ul>
  
  <p>See an screenshot of my ODBC administrator 
  <img src="https://i.imgur.com/4Ajq4e8.png" alt="ODBC administrator"> 
  and the drivers
  <img src="https://i.imgur.com/y5YGlwV.png" alt="the drivers"></p>
  
  <p>I downloaded the ODBC driver for Mac from <a href="https://downloads.teradata.com" rel="nofollow noreferrer">Teradata</a></p>
  
  <p>I use R version 3.5.1 (2018-07-02) and the teradata driver 16.20.</p>
  
  <hr>
  
  <p>What works (on Mac and Windows):
  library(RODBC) </p>
  
  <pre><code>con = odbcConnect(dsn = "name_name"
                    ,uid = rstudioapi::askForPassword("Username")
                    ,pwd = rstudioapi::askForPassword("Password")
                    )
  </code></pre>
  
  <hr>
  
  <p>What doesn't work on Mac (but works on Windows)</p>
  
  <pre><code>con = DBI::dbConnect(odbc::odbc()
                    ,dsn = "name_name"
                    ,uid = rstudioapi::askForPassword("Username")
                    ,pwd = rstudioapi::askForPassword("Password")
                    )
  </code></pre>
  
  <p>On Mac I get the error <code>Error: nanodbc/nanodbc.cpp:950: IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified</code>.</p>
  
  <p>I have also tried other values in my connection string with no luck as described <a href="https://db.rstudio.com/databases/teradata/" rel="nofollow noreferrer">here</a>, e.g:</p>
  
  <pre><code>con = DBI::dbConnect(odbc::odbc()
                    ,Driver = "Teradata"
                    ,Host = "address.here.ok"
                    ,DBName = "name_name"
                    ,uid = rstudioapi::askForPassword("Username")
                    ,pwd = rstudioapi::askForPassword("Password")
                    )
  </code></pre>
  
  <p>Thankyou in advance. </p>
  
  <p><strong>Edit: update</strong></p>
  
  <p>Based on suggestions from @TallTed I checked the two locations where DBI will “look” for the odbc file. </p>
  
  <ul>
  <li><code>/usr/local/etc/</code> directory has files <code>odbc.ini</code> and <code>odbcinst.ini</code> but they’re completely empty</li>
  <li><code>/etc/</code> had neither <code>odbc.ini</code>  or <code>odbcinst.ini</code></li>
  </ul>
  
  <p>I also looked in the locations @TallTed suggested the DBI library would look:</p>
  
  <ul>
  <li><code>/Users/*/Library/ODBC</code> has both <code>odbc.ini</code> and <code>odbcinst.ini</code>.  <code>odbc.ini</code> is filled in with information and <code>odbcinst.ini</code> doesn't have much.</li>
  <li><code>/Library/ODBC/</code> only has <code>odbcinst.ini</code> which is filled with information and an empty folder called <code>ODBCDataSources</code> (not sure if there are hidden files in there).</li>
  <li><code>/Users/*/.odbc.ini</code> exists with nothing in it, I couldn’t open <code>/Users/*/.odbcinst.ini</code></li>
  </ul>
  
  <p>So far, in <code>/usr/local/etc/</code> I removed <code>odbcinst.ini</code> and <code>odbc.ini</code> and crated the following symlinks:</p>
  
  <ul>
  <li>(link to odbc.ini file)<code>ln -s /Users/*/Library/ODBC/odbc.ini /usr/local/etc</code></li>
  <li>(link to odbcinst.ini file)<code>ln -s /Library/ODBC/odbcinst.ini /usr/local/etc</code></li>
  <li>(link to ODBCDataSources folder) <code>ln -s /Library/ODBC/ODBCDataSources /usr/local/etc</code></li>
  </ul>
  
  <p>I couldn't create symlinks into <code>/etc/</code> folder for example I got the error:</p>
  
  <ul>
  <li><code>ln: /etc/odbc.ini: Permission denied</code></li>
  </ul>
  
  <p>Now I get <code>Error: nanodbc/nanodbc.cpp:950: HY000: [Teradata][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function.</code></p>
  
  <p><strong>Edit 2: solution</strong></p>
  
  <pre><code>con = DBI::dbConnect(odbc::odbc()
                 ,driver = "/Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib"
                 ,DBCName = "address.goes.here"
                 ,MechanismName = "ldap"
                 ,uid = rstudioapi::askForPassword("Username")
                 ,pwd = rstudioapi::askForPassword("Password"))
  </code></pre>
  
  <p>The path <code>/Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib</code> is just from ODBC Administrator > Drivers tab</p>