Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting MS SQL Server using connectorx in python

I am facing issues while trying to connect with MSSQL Server using connectorx package in python. I have already verified all the connection details through MS SQL Server Management Studio. I have installed version connectorx version 0.2.3

import urllib.parse
import connectorx as cx
mssql_url = f"mssql://{urllib.parse.quote_plus('User ID')}:{urllib.parse.quote_plus('Password')}@Server URL:1433/Database"
query = "SELECT * FROM table"
df = cx.read_sql(mssql_url, query)

Output of the script: [2022-01-27T12:02:13Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:14Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:14Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:16Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:19Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:26Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 [2022-01-27T12:02:38Z ERROR tiberius::tds::stream::token] message=Login failed for user 'User ID'. code=18456 Traceback (most recent call last): File "", line 1, in File "/app/path/xxxxxxxx/dev/lib/python3.8/site-packages/connectorx/init.py", line 118, in read_sql result = _read_sql( RuntimeError: Timed out in bb8

like image 966
kanishka kartikeya Avatar asked Jul 31 '26 20:07

kanishka kartikeya


1 Answers

I had issues using ConnectorX when attempting to connect to an Azure Sql db, although the following ended up working for me:

mssql://<user>:<password>@<server>:<port>/<database>?driver=ODBC+Driver+17+for+SQL+Server&encrypt=true

Adding &encrypt=true did the trick

like image 182
marko0o Avatar answered Aug 03 '26 09:08

marko0o



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!