How to query Azure sql DB using Synapse Notebooks

Jani Hämäläinen 80 Reputation points
2025-02-14T08:35:51.3333333+00:00

I want to query my azure sql db from azure synapse notebook. I have linked connection working and can use copy activities to read and write data from said synapse workspace to that db. What i would like to do is query that db straight from notebooks so i dont have to make copy pipeline for the tables i want to read.

import pyodbc
pyodbc.drivers()
conn = pyodbc.connect("Driver={ODBC Driver 18 for SQL Server};Server=tcp:MyServer.database.windows.net,1433;Database=MyDB;Uid=MyUserName;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryIntegrated")

connection_string = "Driver={ODBC Driver 18 for SQL Server};Server=tcp:your_server.database.windows.net,1433;Database=your_database;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=60;"

i get error with both connection strings. (I would prefer the latter for no username)

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

with both connection strings. (I would prefer the latter for no username). Error comes in 16 seconds so timeout is not the problem. The username which i am using can connect via SSMS.

Do i need to use pipeline for copying the table to synapse or is it possible to query straight from Notebook?

Azure SQL Database
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,186 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.