0

I am receiving a very common error while trying to connect Microsoft SQL Server using pyodbc. I've tried the solutions suggested here before, but none of them solved my problem.

import pyodbc 
conn = pyodbc.connect('Driver={SQL Server};'
                      'Server= server_name;'
                      'Database= database_name;'     
                      'UID= user_id;'
                      'PWD= password;')


InterfaceError: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]
Login failed for user ' '. (18456) (SQLDriverConnect); [28000] [Microsoft][ODBC SQL Server Driver]
[SQL Server]Login failed for user ' '. (18456)")

When I connect the database via Microsoft SQL Server Management Studio 18 app, below is how I connect. I copy and paste server name, login, and password information to my Python code as shown above. My OS is Windows 10. When I call select @@version, I get Microsoft SQL Server 2014 (SP3-GDR) (KB4583463)...

enter image description here

1 Answer 1

2

Admittedly my python skills are not the best but I'm suspicious of all the single quotes in your connection string.

In the error message Login failed for user ' ' is that blank value for the use what you actually see or have you stripped that out? If that's what you actually see then I think your connection string is malformed.

Refer to the sample here for how to build out a connection string.

Sign up to request clarification or add additional context in comments.

1 Comment

Just figured it out a minute ago and came here to delete the post. It tuned out, you already posted the answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.