Error 28000: Login failed for user DOMAIN\\user with pyodbc
<p>I am trying to use Python to connect to a SQL database by using Window authentication. I looked at some of the posts here (e.g., <a href="https://stackoverflow.com/questions/10000256/failed-to-login-as-domain-computername-pyodbc-with-py2exe">here</a>), but the suggested methods didn't seem to work.</p>

<p>For example, I used the following code:</p>

<pre><code>cnxn = pyodbc.connect(driver='{SQL Server Native Client 11.0}',
                      server='SERVERNAME', 
                      database='DATABASENAME',               
                      trusted_connection='yes')
</code></pre>

<p>But I got the following error:</p>

<pre><code>Error: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]
Login failed for user 'DOMAIN\\username'. (18456) (SQLDriverConnect); [28000] [Microsoft]
[SQL Server Native Client 11.0][SQL Server]Login failed for user 'DOMAIN\\username'. 
(18456)") 
</code></pre>

<p>(<em>Note that I replaced the actual domain name and user name with <code>DOMAIN</code> and <code>username</code> respectively, in the error message above.</em>)</p>

<p>I also tried using my <code>UID</code> and <code>PWD</code>, which led to the same error. </p>

<p>Lastly, I tried to change the service account by following the suggestion from the link above, but on my computer, there was no <code>Log On</code> tab when I went to the <code>Properties</code> of <code>services.msc</code>. </p>

<p>I wonder what I did wrong and how I can fix the problem.</p>