Failed to Login as 'Domain\ComputerName' pyodbc with py2exe

Go To


Ok so I have a script that connects to a mssql db and i need to run as a service which I have already accomplished but when I run it as a service it overrides my credentials that I have put in when i connect to the db with the ad computer account.

It runs perfect when i run it on its own and not as a service.

My Connection String is:

'DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;UID=DOMAIN\myusername;PWD=A;Trusted_Connection=True'

The Error is:

Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'DOMAIN\COMPUTERNAME')

Any Advice?

2012-04-03 19:46
by ChrisMcKenzie
What is your ODBC connection string? What error messages you see in the event log - Anthony Kong 2012-04-03 20:02
'DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName;UID=USERNAME;PWD=PASSWORD;Trusted_Connection=True - ChrisMcKenzie 2012-04-03 20:06
Login failed for user 'CORE\DEEPTHOUGHT - ChrisMcKenzie 2012-04-03 20:07
You probably should mention the version of MSSQL server you are usin - Anthony Kong 2012-04-03 20:27


The following connection string will use Windows authentication, using the account running the service to authenticate with the database. Change the service account to one that has database access:

'DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName;Trusted_Connection=yes'

To change service account:

  • Start -> Run -> services.msc
  • Right-click service -> Properties
  • Log On tab
  • OK/Apply to save changes

Screenshot of window to change service account

2012-04-03 20:15
by Bryan
theunilife mentioned 'overrides my credentials' in the question. He want to use the 'RunAs' credential in the job. It implies he want to use trusted connection - Anthony Kong 2012-04-03 20:16
@AnthonyKong I interpreted it as he wanted to use the UID and PWD values...either way my answer is updated to include both methods for authentication - Bryan 2012-04-03 20:20
Anthony was right Thanks Alot - ChrisMcKenzie 2012-04-03 20:24


In the last project I worked on, I found that DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName is sufficient to initiate a db connection in trusted mode.

If it still does not work, it is probably either

1) the account DEEPTHOUGHT on mssql server is not set up properly.

2) the runAs in the service is not set up properly (why error message mentions 'ComputerName' instead of 'DEEPTHOUGHT'?)

2012-04-03 20:36
by Anthony Kong