Forum Discussion

v-jdubey's avatar
v-jdubey
Microsoft Employee
1 year ago
Solved

Not Able to connect Fabrib database using C# .Net Core API

I am developing RESTful services using a C# .NET Core API. The application connects to a Microsoft Fabric Analytics database using ADO.NET. In my local development environment, the database connectio...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi v-jdubey ,

    Thank you for reaching out to the Microsoft Fabric Community forum.

     

    Based on your explanation, it appears the issue arises when your .NET Core API, hosted on Azure App Service, attempts to connect to a Microsoft Fabric Warehouse SQL endpoint using ManagedIdentityCredential. While it works locally, it fails in Azure with the error “Could not login because the authentication failed”despite successfully acquiring an access token.This typically indicates a permissions or identity scope issue. Below are recommended steps to address it:

     

    In the Azure portal, navigate to your App Service → Identity → System assigned → Enable. This will generate an Azure AD identity for the app. Note the Object ID for permission assignment. Please refer the following documentation for your reference:Managed Identities - Azure App Service | Microsoft Learn

     

    In your Fabric workspace, navigate to the target Warehouse → More options (⋯) → Permissions. Add the App Service’s Managed Identity with Admin or Contributor role. Also ensure the identity has workspace-level permissions.

     Permission model - Microsoft Fabric | Microsoft Learn

     

    Use the correct Fabric SQL endpoint (typically ends with .sql.azuresynapse.net). Do not include username/password in the connection string when using Azure AD tokens.

    Warehouse Connectivity - Microsoft Fabric | Microsoft Learn

     

    Your use of ManagedIdentityCredential is appropriate for Azure-hosted environments. Just ensure this logic is environment-specific and that your local development uses DefaultAzureCredential only.

    Please refer the following link: ManagedIdentityCredential Class (Azure.Identity) - Azure for .NET Developers | Microsoft Learn

    By following these steps and ensuring that the Managed Identity has appropriate access to both the workspace and warehouse, you should be able to resolve the login authentication issue.

     

    Hope this helps. Please reach out for further assistance.

    If this post helps, then please consider to Accept as the solution to help the other members find it more quickly and a kudos would be appreciated.

     

    Thank you.