Python Forum
Unable to login to remote SQL Server database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to login to remote SQL Server database
#1
Hello everyone,

I am trying to connect to a remote database in a SQL Server Engine for the first time, but I am struggling with it in Python 3.

As a start, I have installed 'Microsoft ODBC Driver 17 for SQL Server' in a Debian OS and everything seems to be setup without problem, at least there was no issues following all the steps of that tutorial.

Then I installed the pyodbc module, and tried to connect to the remote database, but I am always reciving this error:

Error:
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
This is the statement used:

SQLdbconnection = pyodbc.connect(r'DRIVER={ODBC Driver 17 for SQL Server};SERVER="host\service";DATABASE=database;UID="user";PWD="password"')
I have another Python 2 script running from another place made from another person that uses FreeTDS driver instead, and its working fine, for the same DB and credentials.

From this machine where I am, in /etc/odbcinst.ini I have:

Output:
[ODBC Driver 17 for SQL Server] Description=Microsoft ODBC Driver 17 for SQL Server Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.2.1 UsageCount=1 [ODBC] Trace = Yes TraceFile = /dev/stdout
Note: I add those last 3 lines to get a verbose mode, while it tries to connect.

Anyone knows how to solve this?
Reply
#2
So i was adding unnecessary quotes, the right statement is suppose to be in python 3:

SQLdbconnection = pyodbc.connect(r'DRIVER={ODBC Driver 17 for SQL Server};SERVER=host\service;DATABASE=database;UID=user;PWD=password')
I hope that this could help others, I have spend 2 days with this ....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to connectDjango to mysql server sureshpython 0 152 Apr-09-2024, 07:30 PM
Last Post: sureshpython
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 365 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Database connection problems [login, PyQt5, PySql] gradlon93 5 692 Dec-15-2023, 05:08 PM
Last Post: deanhystad
  pysql connection to cloud server database times out Pedroski55 9 4,709 Oct-11-2021, 10:34 PM
Last Post: Pedroski55
  How to take the tar backup files form remote server to local server sivareddy 0 1,895 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,259 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  python3 emulate tail -f on remote server... support required anna 0 1,647 Jul-01-2020, 06:42 AM
Last Post: anna
  connect to remote database via python script sunstar20 5 5,335 Apr-23-2018, 11:05 AM
Last Post: Gribouillis
  Unable to connect oracle database using python code mayuresh 2 17,076 Jan-27-2018, 11:57 AM
Last Post: mayuresh
  Newbie question for bulk insert into SQL Server database zydjohn 6 12,387 Dec-14-2017, 11:04 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020