0

I am working with python, sqlachemy and MSSQL. For no apparent reason I received the following error, it has only happened twice and I have not been able to replicate it.

/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 519, in do_ping
    cursor.execute(self._dialect_specific_select_one)
sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('HY000', '[HY000] [FreeTDS][SQL Server]Unknown error (0) (SQLExecDirectW)')
(Background on this error at: http://sqlalche.me/e/dbapi)/n"

Does anyone know why this could happen? Any ideas on how to fix this issue?

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • have you checked your MSSQL database is accepting incoming connections? – julian Apr 12 '22 at 18:54
  • @julian yes, it is accepting incomming connections without problem. The error has not reappeared but I'm worried about not preventing it in future occasions. – Laura Ochoa Apr 12 '22 at 19:19
  • 1
    What version of FreeTDS are you using? Some Linux repos provide rather old versions of some components. For example, the Ubuntu 20.04 repo distributes FreeTDS 1.1.6 (almost 3 years old) although the latest version is 1.3.9. Note also that SQLAlchemy's CI testing does not cover FreeTDS ODBC; it only tests Microsoft's "ODBC Driver x for SQL Server". – Gord Thompson Apr 12 '22 at 19:55
  • @GordThompson I'm using TDS Version 8.0 and the docker image is python:3.7-slim-bullseye. – Laura Ochoa Apr 12 '22 at 20:22
  • 1
    I was talking about the version of the FreeTDS software itself. Version 8.0 refers to the version of the TDS *protocol* that is used to communicate with the SQL Server instance. So, both FreeTDS 1.1.6 and FreeTDS 1.3.9 implement the various versions of the TDS protocol (4.2, 7.0, 7.1, etc.) but more recent releases of FreeTDS may have fixed bugs in older versions. – Gord Thompson Apr 12 '22 at 20:34
  • TDS protocol version 8.0 is actually not valid due to some confusion years ago: https://www.freetds.org/userguide/ChoosingTdsProtocol.html It cannot be used in versions 1.3+, where it used to map to 7.1. – FlipperPA Apr 14 '22 at 19:11
  • @LauraOchoa Have you tried connecting with the FreeTDS `tsql` utility from the machine also running SQL Alchemy? Am I right in seeing that this only occurs intermittently and not every time? – FlipperPA Apr 14 '22 at 19:12
  • 1
    @FlipperPA Yes, using tsql seems to have fixed it. Thanks – Laura Ochoa Apr 20 '22 at 15:40

0 Answers0