Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am trying to connect to the Azure SQL data base from Fabric notebook using my credentials. I was hoping my logged in credentials will be used to get the data from the server. I am able to connect using SSMS.
PYODBC_DRIVER = "{ODBC Driver 18 for SQL Server}"
pyOdbcConnString = "DRIVER={0};SERVER={1};DATABASE={2};Encrypt=yes;Authentication=ActiveDirectoryInteractive;UID=xx@xx.com".format(
PYODBC_DRIVER,
ServerName,
DatabaseName,
)
I am getting following error.
OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Hi @sambathraj
I haven't tested Microsoft Entra ID authentication yet. I tested with SQL authentication with below code in a notebook successfully. You may try changing the connection string accordingly.
import pyodbc
servername = 'your server name'
databasename = 'your db name'
username = 'sql user name'
password = 'xxxxxx'
connection_string = f"Driver={{ODBC Driver 18 for SQL Server}};Server=tcp:{servername}.database.windows.net,1433;Database={databasename};Uid={username};Pwd={password};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
query_string = 'select top 10 * from SalesLT.ProductCategory'
conn = pyodbc.connect(connection_string)
cursor = conn.cursor()
cursor.execute(query_string)
resultList = cursor.fetchall()
for row in resultList:
print(row)
You can try adding connection timeout to the connection string. Also ensure that your client IP address has been added in Firewall rules of the Azure SQL database or server.
connection_str = "Driver={ODBC Driver 18 for SQL Server};Server={server};Database={Database};UID={username};Authentication=ActiveDirectoryInteractive;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
Hope this would be helpful. Let me know if you have any questions.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
SQL Authentication works fine. I was trying to use Managed Identity / logged in user Entra ID.