title: Connecting to MS SQL Server with Windows Authentication using Python?
body: <p>How do I connect MS SQL Server using Windows Authentication, with the pyodbc library?</p>
  
  <p>I can connect via MS Access and SQL Server Management Studio, but cannot get a working connection ODBC string for Python.</p>
  
  <p>Here's what I've tried (also without <code>'Trusted_Connection=yes'</code>):</p>
  
  <pre><code>pyodbc.connect('Trusted_Connection=yes',
                 driver='{SQL Server}', server='[system_name]',
                 database='[databasename]')
  
  pyodbc.connect('Trusted_Connection=yes', uid='me',
                 driver='{SQL Server}', server='localhost',
                 database='[databasename]')
  
  pyodbc.connect('Trusted_Connection=yes',
                 driver='{SQL Server}', server='localhost',
                 uid='me', pwd='[windows_pass]', database='[database_name]')
  
  pyodbc.connect('Trusted_Connection=yes',
                 driver='{SQL Server}', server='localhost',
                 database='[server_name]\\[database_name]')
  
  pyodbc.connect('Trusted_Connection=yes',
                 driver='{SQL Server}', server='localhost',
                 database='[server_name]\[database_name]')
  
  pyodbc.connect('Trusted_Connection=yes',
                 driver='{SQL Server}',
                 database='[server_name]\[database_name]')
  </code></pre>