Flask pyodbc showing "Login failed for user" when using "TRUSTED_CONNECTION=Yes"

104 views Asked by At

I have the following connection: cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=nameofmyserver;DATABASE=nameofmydb;TRUSTED_CONNECTION=Yes;")

The Flask app is on IIS and has Windows Authentication enabled.

On one route, I return request.environ.get('REMOTE_USER').split('\\')[1] which returns my username as expected

When I try and connect to MSSQL I get an error as follows:

[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'DOMAIN\\7A6AUSRV02$'.

Any suggestions on how to resolve this issue?

I have tried changing the driver to no avail

What I am trying to do is list stored procedures that the current logged in user has access to

1

There are 1 answers

5
David Browne - Microsoft On

This

DOMAIN\7A6AUSRV02$

Is the computer account for the server named 7A6AUSRV02. It's a domain account, and can be granted access to SQL Server like any other Windows domain account. eg

create login [DOMAIN\7A6AUSRV02$] from windows
create user [DOMAIN\7A6AUSRV02$] for login [DOMAIN\7A6AUSRV02$] 

You should have a database role that defines the database permissions needed for the flask app, and you should add this user to that role, eg

  alter role MyFlaskApp add member [DOMAIN\7A6AUSRV02$]