Forum Discussion
Connect to Azure SQL using Microsoft EntraID from Fabric Notebook
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;[email protected]".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)')
2 Replies
- AnonymousNot applicable
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!- sambathrajRegular Visitor
SQL Authentication works fine. I was trying to use Managed Identity / logged in user Entra ID.