To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Can we connect to azure sql db from fabric notebook and insert data using stored procedures from fabric notebook itself
Solved! Go to Solution.
Hi @yashaswi_raj,
Yes. You can connect from a Fabric notebook to Azure SQL DB and call stored procedures. The most reliable pattern is Python + pyodbc with a Microsoft Entra ID access token.
# In a Python cell %pip install pyodbc import struct, pyodbc from notebookutils import mssparkutils # alias of mssparkutils in Fabric server = "<yourserver>.database.windows.net" database = "<yourdb>" # Get Entra access token for Azure SQL token = mssparkutils.credentials.getToken("https://database.windows.net/") # Fabric NotebookUtils <https://learn.microsoft.com/en-us/fabric/data-engineering/notebook-utilities> # Convert token for ODBC Driver 18 (SQL_COPT_SS_ACCESS_TOKEN = 1256) exptoken = b"".join(bytes([c]) + b"\x00" for c in token.encode("utf-8")) token_struct = struct.pack("=i", len(exptoken)) + exptoken conn_str = ( "Driver={ODBC Driver 18 for SQL Server};" f"Server={server};Database={database};" "
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, please mark this as the solution.
Hi @yashaswi_raj,
Yes. You can connect from a Fabric notebook to Azure SQL DB and call stored procedures. The most reliable pattern is Python + pyodbc with a Microsoft Entra ID access token.
# In a Python cell %pip install pyodbc import struct, pyodbc from notebookutils import mssparkutils # alias of mssparkutils in Fabric server = "<yourserver>.database.windows.net" database = "<yourdb>" # Get Entra access token for Azure SQL token = mssparkutils.credentials.getToken("https://database.windows.net/") # Fabric NotebookUtils <https://learn.microsoft.com/en-us/fabric/data-engineering/notebook-utilities> # Convert token for ODBC Driver 18 (SQL_COPT_SS_ACCESS_TOKEN = 1256) exptoken = b"".join(bytes([c]) + b"\x00" for c in token.encode("utf-8")) token_struct = struct.pack("=i", len(exptoken)) + exptoken conn_str = ( "Driver={ODBC Driver 18 for SQL Server};" f"Server={server};Database={database};" "
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, please mark this as the solution.
thanks for the answer, @tayloramy
So the Fabric workspace identity can't be used as a authentication . right?
Hi @yashaswi_raj,
A fabric workspace identity is a service principal in azure, so if it is granted access to the Azure SQL server resource, it should be able to be used anywhere where a service principal is supported.
Workspace identity - Microsoft Fabric | Microsoft Learn
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, please mark this as the solution.
Hi @yashaswi_raj ,
Thanks for reaching out to the Microsoft fabric community forum.
I would also take a moment to thank @tayloramy , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
Yes, The Fabric workspace identity is basically a service principal in Azure. If you add it as a user in your Azure SQL Database and give it the right permissions (like EXECUTE on your stored procedures), you can use it for authentication from the notebook, just like any other service principal.
Best Regards,
Community Support Team
User | Count |
---|---|
15 | |
15 | |
12 | |
9 | |
7 |
User | Count |
---|---|
38 | |
30 | |
27 | |
21 | |
15 |