-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hello guys, I need some help with the problem bellow.
I tried to connect on sqlserver using this connect_string:
But received this error:
$ python3
Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import mssql_python
Establish a connection
Specify connection string
connection_string = "SERVER=localhost,1433;DATABASE=master;UID=sa;PWD=Passw0rd;Encrypt=yes;"
connection = mssql_python.connect(connection_string)
Traceback (most recent call last):
File "", line 1, in
File "/home/lpbispo/.local/lib/python3.12/site-packages/mssql_python/db_connection.py", line 36, in connect
conn = Connection(connection_str, autocommit=autocommit, attrs_before=attrs_before, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lpbispo/.local/lib/python3.12/site-packages/mssql_python/connection.py", line 80, in init
self._conn = ddbc_bindings.Connection(self.connection_str, self._pooling, self._attrs_before)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2749
---> mssql-python==0.8.1
---> WSL ubuntu
---> sqlserver running and accepting connections by management studio
I did not find any example where the database port is explicit on connect string.
I looked here:
- Connection · microsoft/mssql-python Wiki;
- mssql-python/tests/test_003_connection.py at main · microsoft/mssql-python;
- mssql-python/mssql_python/connection.py at main · microsoft/mssql-python.
I am repoting this because some databases may not be on default port
"By default, MS SQL Server listens on port 1433 for TCP/IP connections. However, this can be changed for various reasons, including security considerations or to accommodate multiple instances of SQL Server on the same machine." https://aextestusw.autodesk.com/default-port-mssql