Remote connection to MS SQL – Error using pyodbc vs success using SQL Server Management Studio

Try specifying the port:

import pyodbc

server = r"xxxER\xxxSQLSERV"
db = "xxxDB"
user = "xxx"
password = "xxxx"
port = "1433"
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';PORT=' + port + ';DATABASE=' + db +';UID=' + user + ';PWD=' + password)

If you’re still having issues, try using the IP or FQDN of the server.

Leave a Comment