To diagnose, we usually need to know the following, including version numbers. On Windows, be
sure to specify 32-bit Python or 64-bit:
Python: 3.11.2 64-bit
pyodbc: 4.0.35
OS: Python on Windows 10 Pro x64
DB: MSSQL Server 2019 on docker container - image: mssql/server:2019-latest
driver: ODBC Driver 17 for SQL Server
On Container: unixODBC 2.3.11
Issue
I have the docker container in Synology NAS (AMD 64), IP, example: 192.169.0.3 port for container 2443
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)')
When I try to connect with DSN (DSN is configured in container, MSSQLServerDatabase is the name of DSN):
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 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:
Python: 3.11.2 64-bit
pyodbc: 4.0.35
OS: Python on Windows 10 Pro x64
DB: MSSQL Server 2019 on docker container - image: mssql/server:2019-latest
driver: ODBC Driver 17 for SQL Server
On Container: unixODBC 2.3.11
Issue
I have the docker container in Synology NAS (AMD 64), IP, example: 192.169.0.3 port for container 2443
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)')
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!