Mssql-docker: Connection with pyodbc does not work

Created on 1 Sep 2017  路  5Comments  路  Source: microsoft/mssql-docker

The oss-drivers pyodbc does not work, neither on native ubuntu 16.04 nor in docker image provided!.

Please fix.

Str Out = 0x7ffc7e44b170
Str Out Max = 2048
Str Out Ptr = (nil)
Completion = 0
UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'

        DIAG [08001] [Microsoft][ODBC Driver 13 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF].

        DIAG [HYT00] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

        DIAG [01S00] [Microsoft][ODBC Driver 13 for SQL Server]Invalid connection string attribute



     DIAG [08001] [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

[ODBC][83][1504285617.876218][SQLDriverConnect.c][1507]
Exit:[SQL_ERROR]
[ODBC][83][1504285617.876392][SQLGetDiagRec.c][680]
Entry:
Connection = 0x1d92340
Rec Number = 1
SQLState = 0x7ffc7e44bd60
Native = 0x7ffc7e44bd4c
Message Text = 0x7ffc7e44bd70
Buffer Length = 1023
Text Len Ptr = 0x7ffc7e44bd4a
[ODBC][83][1504285617.877145][SQLGetDiagRec.c][717]
Exit:[SQL_SUCCESS]
SQLState = HYT00
Native = 0x7ffc7e44bd4c -> 0
Message Text = [[unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired]
[ODBC][83][1504285617.877556][SQLFreeHandle.c][284]
Entry:
Handle Type = 2
Input Handle = 0x1d92340
[ODBC][83][1504285617.877810][SQLFreeHandle.c][333]
Exit:[SQL_SUCCESS]
Traceback (most recent call last):
File "connect.py", line 6, in
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';PORT=1443;UID='+username+';PWD='+ password+';PORT=1433')
pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

mssql-server-linux

All 5 comments

Same issue here, I'm giving up and using MySQL. At least it actually works.

Having the same login timeout problem connecting from MacOS High Sierra to microsoft/mssql-server-linux running locally on Docker.

django.db.utils.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 13 for 
SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Driver: ODBC Driver 13 for SQL Server

Python dependencies (trying test a Django application):

  • pyodbc: 4.0.21
  • django-pyodbc-azure: 1.11.0.0

Homebrew dependencies:

  • msodbcsql: 13.1.9.0
  • mssql-tools 14.0.6.0

I've confirmed that I can connect to the DB using the DbVisualizer application + jTDS JDBC driver.

Sorry, was actually able to connect from a Python shell directly using pyodbc. There must be something wrong in the way django-pyodbc-azure is configuring the connection

Sorry, was actually able to connect from a Python shell directly using pyodbc. There must be something wrong in the way django-pyodbc-azure is configuring the connection

Do you have the code that you used with pyodbc? I have been unable to get the following to work against a docker instance running mssql

import pyodbc 
server = 'localhost' 
database = 'MyDB'
username = 'SA'
password = '******************'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()

cursor.execute("SELECT * from MyDB.dbo.mytable;") 
row = cursor.fetchone()
while row: 
    print(row)
    row = cursor.fetchone()

actually: I got this to work with django-pyodbc-azure. localhost does not work, but using 0.0.0.0 works.

I am running microsoft/mssql-server-linux:2017-latest on mac os 10.13.6 and i am mapping 1433 to host

    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': config("MSSQL_DB_NAME", default="MyDb"),
        'USER': config("MSSQL_DB_USER", default="SA"),
        'PASSWORD': config("MSSQL_DB_USER", default=""),
        'HOST' : "0.0.0.0", 
        'PORT': '1433',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server'
        },
    }
Was this page helpful?
0 / 5 - 0 ratings