Pyodbc: Login Timeout Error
Microsoft's ODBC drivers for SQL Server do not use a PORT=
parameter. The port number, if any, is appended to the server name/IP with a comma, e.g.,
SERVER=xxxTest-SRV,51333;
Login timeout expired error when accessing MS SQL db via sqlalchemy and pyodbc
The problem might be DNS related, as you can read here.
Try to use an IP address, instead of the hostname, in the connection string, or check your DNS configuration.
Unable to set up SQL Server backend using pyodbc for airflow on a Centos 7 server
This problem got fixed by internal request, it was a firewall issue.
Error while connecting to the Sql Server with pyodbc
There was a problem with DNS. I used the IP address of the server instead, works fine now.
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.
[Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
My connection string looks different:
"DRIVER={ODBC Driver 17 for SQL Server};SERVER=myserver;DATABASE=mydb;UID=myuser;PWD=mypassword"
leeds to
import pyodbc
connection = pyodbc.connect("DRIVER={ODBC Driver 17 for SQL Server};SERVER=myserver;DATABASE=mydb;UID=myuser;PWD=mypassword", autocommit=True)
Instead of UID you are using username, etc. All words starting with 'my' have to be replaced with the actual db, user and password. You should also remove the Trusted_Connection=True;
part as Panagiotis Kanavos pointed out in the comment. This says you are using your windows-user to authenticate (which is obviously not available on linux).
Related Topics
Get All Modules/Packages Used by a Python Project
Python Gdal 2.1 Installation on Ubuntu 16.04
How to Close a Socket Left Open by a Killed Program
Get Mouse Deltas Using Python! (In Linux)
How to "Watch" a File for Modification/Change
Python Script to List Users and Groups
Environment Variables When Script Run by Cron
Schedule Python Script with Crontab
Standalone Python Applications in Linux
Changing the Process Name of a Python Script
Give the Python Terminal a Persistent History
How to Make My Python Module Available System Wide on Linux
Setuid Bit on Python Script:Linux VS Solaris
Ipython Notebook on Linux Vm Running Matplotlib Interactive with Nbagg
How to Install Python Developer Package