title: When connecting R to Microsoft SQL Server, do you have to use a DSN?
body: <p>I want to connect R to SQL Server so I can export some R data frames as tables to SQL Server.</p>
  <p>From a few online tutorials, I've seen they use the <code>RODBC</code> package, and it seems that you first need to create an ODBC name first, by going to ODBC Data sources (64-bit) &gt; System DSN &gt; Add &gt; SQL Server Native Client 11.0&gt; and then insert your specifications.</p>
  <p>I have no idea how databases are managed, so forgive my ignorance here.. my <strong>question is:</strong> if there is already a database/server set up on SQL Server, particularly also where I want to export my R data to, do I still need to do this?</p>
  <p>For instance, when I open Microsoft SQL Server Management Studio, I see the following:</p>
  <ul>
  <li>Server type: Database Engine</li>
  <li>Server name: example.server.myorganization.com</li>
  <li>Authentication: SQL Sever Authentication</li>
  <li>Login: organization_user</li>
  <li>Password: organization_password</li>
  </ul>
  <p>After logging in, I can access a database called &quot;Organization_Division_DBO&quot; &gt; Tables which is where I want to upload my data from R as a table. Does this mean the whole ODBC shebang is already setup for me, and I can skip the steps <a href="https://turbofuture.com/computers/Connect-to-SQL-Server-from-R" rel="nofollow noreferrer">mentioned here</a> where an ODBC needs to be set up?</p>
  <p>Can I instead use the code <a href="https://stackoverflow.com/a/47648510/16286004">shown here</a>:</p>
  <pre><code>library(sqldf)
  library(odbc)
  con &lt;- dbConnect(odbc(),
                   Driver = &quot;SQL Server&quot;,
                   Server = &quot;example.server.myorganization.com&quot;,
                   Database = &quot;Organization_Division_DBO&quot;,
                   UID = &quot;organization_user&quot;,
                   PWD = &quot;organization_password&quot;)
  dbWriteTable(conn = con, 
               name = &quot;My_R_Table&quot;, 
               value = )  ## x is any data frame I have in R
  </code></pre>
  <p>I note that on <a href="https://support.rstudio.com/hc/en-us/articles/214510788-Setting-up-R-to-connect-to-SQL-Server-" rel="nofollow noreferrer">this page</a> they use a similar code to above (what is port number?) and also there is some mention &quot;that there is also support for DSNs&quot;, so I am a little confused. Also, is there any advantage/disadvantage over using the <code>ODBC</code> package over the <code>RODBC</code> package to do this?</p>