Azure Function connection string to Azure Data Explorer

Rene Prins 46 Reputation points
2024-02-16T08:21:39.08+00:00

Hi, I do have an Azure Function in C# with Kusto bindings to get data from Azure Data Explorer, in my local.settings.json I added the connection string like this: "ConnectionStrings"``: {   "KustoConnectionString": ``"https://xxxxx.westeurope.kusto.windows.net/databaseName;Fed=true;Accept=true" } And locally this is working as expected, I'm able to retrieve data from Azure Data Explorer. After deployment to Azure, I'm adding the same connection string to the Configuration, if I'm doing a test run I'm getting a 500 error with the following error message: Unable to open a web page using xdg-open, gnome-open, kfmclient or wslview tools in sudo mode. Please run the process as non-sudo user. I tried to add System Identity on in the Function App and added this in ADX under Permissions so the Function App do have enough permissions to access the database, unfortunately I got the same result. Am I connecting on the proper way to ADX or is the error related to something else?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,353 questions
Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
487 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,156 Reputation points
    2024-02-16T17:24:10.27+00:00

    Rene Prins Thanks for posting your question in Microsoft Q&A. I assumed you followed doc Azure Data Explorer bindings for Azure Functions and in-process and isolated samples in your function app. When deploying to Azure, make sure to add KustoConnectionString as described in https://learn.microsoft.com/en-us/azure/data-explorer/kusto/api/connection-strings/kusto#user-authentication-properties and also set ManagedServiceIdentity to system for system-assigned managed identity (reference: Attributes).

    [KustoInput(Database: "productsdb", KqlCommand = "declare query_parameters (name:string);GetProductsByName(name)", KqlParameters = "@name={name}", Connection = "KustoConnectionString", ManagedServiceIdentity = "system")]
    

    Hope you already assigned Viewer permission for system-assigned managed identity for input binding like described here. Please let me know if you still face any issues (any additional details like code snippet, full exception info including stack trace would help).

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Achraf Ben Alaya 976 Reputation points MVP
    2024-02-16T08:53:40.4033333+00:00

    The error message you're encountering, "Unable to open a web page using xdg-open, gnome-open, kfmclient, or wslview tools in sudo mode," suggests that there might be an issue with how the Azure Function is trying to open a web page, possibly related to debugging or logging. However, this error message doesn't seem directly related to the configuration of your Kusto connection string. The connection string format you provided for Kusto in your local.settings.json file appears to be correct. To troubleshoot the issue further, here are some steps you can take:

    1. Check Azure Function Logs: Look at the logs of your Azure Function in the Azure portal to see if there are any error messages or exceptions related to the Kusto connection. This can provide more insight into what might be going wrong during the execution of your function.
    2. Review Connection String Configuration: Double-check the configuration of your Kusto connection string in the Azure portal. Ensure that the connection string is correctly formatted and that it includes the necessary authentication and authorization information to access your Azure Data Explorer database.
    3. Verify Permissions: Ensure that the Azure Function has the necessary permissions to access the Azure Data Explorer database. You mentioned adding a System Identity to the Function App and configuring permissions in Azure Data Explorer, which is the right approach. Make sure that the permissions are set up correctly and that the Function App is using the correct identity when accessing the database.
    4. Test Connection String Locally: Try running your Azure Function locally with the same connection string configuration that you're using in Azure. This can help determine if the issue is specific to the Azure deployment or if there's a problem with the connection string itself.
    5. Check for Environment Differences: Make sure there are no differences between your local development environment and the Azure environment that could be causing the issue. Pay attention to any environment variables or configuration settings that might affect how your Azure Function behaves. Consider Alternative Authentication Methods: Depending on how your Azure Data Explorer database is configured, you might need to use different authentication methods in your connection string (e.g., Azure Active Directory authentication). Make sure you're using the appropriate authentication method based on your database configuration.

    By following these steps and investigating the possible causes of the issue, you should be able to identify and resolve the problem with connecting to Azure Data Explorer from your Azure Function.