pyodbc
pyodbc copied to clipboard
How to connect Azure Synapse severless DB using service principal and federated credential
trafficstars
Please first make sure you have looked at:
- Documentation: https://github.com/mkleehammer/pyodbc/wiki
- Other issues
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.10.4
- pyodbc: 5.2.0
- OS: ubuntu22.04
- DB: Azure Synapse serverless database
- driver: {ODBC Driver 18 for SQL Server}
Issue
Hi pyodbc expert,
previously I used the code below as your suggestion to connect Azure SQL Server DB successfully.
def bytes2mswin_bstr(value: bytes) -> bytes:
encoded_bytes = bytes(chain.from_iterable(zip(value, repeat(0))))
return struct.pack("<i", len(encoded_bytes)) + encoded_bytes
tokenstruct = bytes2mswin_bstr(token.encode())
conn = pyodbc.connect(connstr, attrs_before = {1256:tokenstruct}, timeout=30)
However, I could not use the same code to connect Azure Synapse Database. What is the recommended way to connect Azure Synapse Database using non secret method?
Often it is easiest to describe your issue as "expected behavior" and "observed behavior".