mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 562 forks source link

Impossible to connect to MSSQL Server 2019 on docker container #1184

Closed cyanezf closed 1 year ago

cyanezf commented 1 year ago

Please first make sure you have looked at:

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

Issue

I have the docker container in Synology NAS (AMD 64), IP, example: 192.169.0.3 port for container 2443

  1. When I try to connect with driver:

import pyodbc conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.169.0.3,2443;UID=SA;PWD=mypassword')

Error: Traceback (most recent call last): File "c:\Users\vm\Desktop\SQL Server\sql-connection.py", line 10, in connection = odbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.169.0.3,2443;UID=SA;PWD=mypassword') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: The wait operation timed out.\r\n (258) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 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. (258)')

  1. When I try to connect with DSN (DSN is configured in container, MSSQLServerDatabase is the name of DSN):

import pyodbc conn = pyodbc.connect('DSN=MSSQLServerDatabase;UID=SA;PWD=mypassword')

Error: Traceback (most recent call last): File "c:\Users\vm\Desktop\SQL Server\sql-connection.py", line 9, in connection = odbc.connect('DSN=MSSQLServerDatabase;UID=SA;PWD=mypassword') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

How you can see, the odbc cannot connect, but when I connect to database with VSCode or SQL Server Management Studio I connect without problems.

Please, can you help me?

Thanks in advance!