Forum Discussion
How to connect Fabric SQL Database in VS Code using C# or Python with non-interactive authentication
- 1 year ago
Hi bhavya5903,
Thanks for sharing your scenario in the Microsoft Fabric Community. I understand you want to connect to a Microsoft Fabric SQL Database from VS Code using non-interactive authentication (Client ID, Client Secret, Tenant ID) instead of the current browser-based interactive login.
In Microsoft Fabric, the supported approach for service-to-service (non-interactive) connections is to use an Azure AD app registration with the Client Credentials flow. You will need to do these below mentioned steps.
Register an application in Azure AD: Go to Azure Portal → Azure Active Directory → App registrations → New registration. Note the Application (client) ID, Directory (tenant) ID. Create a Client Secret under Certificates & secrets.Assign permissions to the app: In the Fabric workspace, grant the Azure AD app the necessary role (e.g., Contributor or Member). Ensure the app has Database permissions in the Fabric SQL endpoint.
Use ClientSecretCredential in your code:
C# example: ClientSecretCredential Class (Azure.Identity) - Azure for .NET Developers | Microsoft Learn.
Python example: azure.identity.ClientSecretCredential class | Microsoft Learn.
Connection string format: Fabric SQL Database uses the Azure SQL connection syntax, so once you have a token from ClientSecretCredential, you can connect via SqlConnection in C# or pyodbc / sqlalchemy in Python.Also, additional documentation links are mentioned below those might be helpful:
What is the SQL analytics endpoint for SQL database in Fabric? - Microsoft Fabric | Microsoft Learn
Microsoft Entra authentication - Azure SQL Database & Azure SQL Managed Instance & Azure Synapse Analytics | Microsoft Learn
Microsoft Entra authentication - Azure SQL Database & Azure SQL Managed Instance & Azure Synapse Analytics | Microsoft Learn
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.
Hi bhavya5903,
Thanks for sharing your scenario in the Microsoft Fabric Community. I understand you want to connect to a Microsoft Fabric SQL Database from VS Code using non-interactive authentication (Client ID, Client Secret, Tenant ID) instead of the current browser-based interactive login.
In Microsoft Fabric, the supported approach for service-to-service (non-interactive) connections is to use an Azure AD app registration with the Client Credentials flow. You will need to do these below mentioned steps.
Register an application in Azure AD: Go to Azure Portal → Azure Active Directory → App registrations → New registration. Note the Application (client) ID, Directory (tenant) ID. Create a Client Secret under Certificates & secrets.
Assign permissions to the app: In the Fabric workspace, grant the Azure AD app the necessary role (e.g., Contributor or Member). Ensure the app has Database permissions in the Fabric SQL endpoint.
Use ClientSecretCredential in your code:
C# example: ClientSecretCredential Class (Azure.Identity) - Azure for .NET Developers | Microsoft Learn.
Python example: azure.identity.ClientSecretCredential class | Microsoft Learn.
Connection string format: Fabric SQL Database uses the Azure SQL connection syntax, so once you have a token from ClientSecretCredential, you can connect via SqlConnection in C# or pyodbc / sqlalchemy in Python.
Also, additional documentation links are mentioned below those might be helpful:
What is the SQL analytics endpoint for SQL database in Fabric? - Microsoft Fabric | Microsoft Learn
Microsoft Entra authentication - Azure SQL Database & Azure SQL Managed Instance & Azure Synapse Analytics | Microsoft Learn
Microsoft Entra authentication - Azure SQL Database & Azure SQL Managed Instance & Azure Synapse Analytics | Microsoft Learn
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.
One key point to add to these instructions is to check that the service principal can in fact login to the Microsoft Fabric SQL Database.
One way to check this is by logging into the database as a service principal with the aest version of SQL Server management Studio.