Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login Timeout Error when connecting to Synapse database using pyodbc python library in Azure synapse notebook via Managed Identity #1341

Closed
hellorohitsharma opened this issue Apr 4, 2024 · 1 comment

Comments

@hellorohitsharma
Copy link

I am running my Python code in Synapse Jupiter notebooks on Azure Synapse. I am trying to connect to Synapse DB with pyodbc library using Managed identity. I am getting Login Timeout Error.

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

  • Python: 2.7.17
  • pyodbc: 4.0.30
  • OS: Azure Synapse VM, 64 bit
  • DB: Synapse DB
  • driver: {ODBC Driver 17 for SQL Server}

Code snippet:
driver='{ODBC Driver 17 for SQL Server}'

try:

conn = pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=#####;DATABASE='+database+';Encrypt=yes;Integrated Security=false;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryMsi;')

conn.autocommit=True
cursor=conn.cursor()
print(f"connection established with the SQL DB")

except Exception as E:
print(f"Error occurred while establishing connections with Synapse DB", E)

Error:
('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Please help me on this.

@v-chojas
Copy link
Contributor

v-chojas commented Apr 4, 2024

Make sure the managed identity is enabled on the VM, and that the server is reachable from it. The "timeout expired" suggests it couldn't connect to the server.

And for the record, "PORT" is NOT a valid connection string option, nor is "Connection Timeout". Where are you getting that from? Here is the list that the driver supports: https://learn.microsoft.com/en-us/sql/connect/odbc/dsn-connection-string-attribute?view=sql-server-ver16

@gordthompson gordthompson closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants