Error in function execution: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Philippe Vlaemminck 6 Reputation points
2024-10-08T08:58:24.1233333+00:00

Hello,
I'm running Visual Code Studio on a Mac, I have a valid Azure Subscription with a SQL Server, a SQL Database that I can access using Azure Data Studio.

I'm struggling already days on this topic.

  1. I have an Azure Function with System-Assigned Managed Identity Enabled.
  2. I have created the user (= name of the Azure Function) in the SQL database `CREATE USER [
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,039 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Pinaki Ghatak 4,380 Reputation points Microsoft Employee
    2024-10-09T08:47:08.5966667+00:00

    Hello @Philippe Vlaemminck

    Based on the error message you provided, it seems like there might be a problem with the login credentials for your SQL Server. To troubleshoot this issue, I would recommend checking the following:

    1. Make sure that the SQL Server firewall is configured to allow traffic from the IP address of your Azure Function. You can do this by going to the Azure portal, navigating to your SQL Server, and clicking on "Firewalls and virtual networks". From there, you can add a new firewall rule to allow traffic from your Azure Function's IP address.
    2. Double-check that the connection string for your Azure Function is correct. You can find the connection string in the Azure portal, under "Configuration" for your Function App. Make sure that the connection string includes the correct server name, database name, and login credentials.
    3. Check that the SQL Server is running and accessible from your machine. You can use Azure Data Studio or another tool to test the connection to your SQL Server.

    That should get you started.


  2. LeelaRajeshSayana-MSFT 15,561 Reputation points Microsoft Employee
    2024-10-14T16:21:39.7733333+00:00

    Hi @Philippe Vlaemminck Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    There are few additional checks you can validate to make sure the System Managed Identity can access the Azure SQL Server.

    1. Enable Microsoft Entra authentication to SQL Database by assigning a Microsoft Entra user as the admin of the server. Please note that this user is different from the Microsoft account you used to sign up for your Azure subscription. It must be a user that you created, imported, synced, or invited into Microsoft Entra ID. You can get the details of the Object ID for the System Managed identity created by running the following Azure CLI command
         azureaduser=$(az ad user list --filter "userPrincipalName eq '<user-principal-name>'" --query [].id --output tsv)
      
      Add this Microsoft Entra user as an Active Directory admin using az sql server ad-admin create command in the Cloud Shell.
         az sql server ad-admin create --resource-group myResourceGroup --server-name <server-name> --display-name ADMIN --object-id $azureaduser
      
    2. Once you create the User into the Database, you would need to provide db_datareader or db_datawriter access to the identity. Please refer the following commands that needs to be executed by logging in through Entra Admin role to the SQL server
         CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
         ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
         ALTER ROLE db_datawriter ADD MEMBER [<identity-name>];
         GO
      
    3. Configure the Azure Function SQL connection string to use Microsoft Entra managed identity authentication. In the application settings of our Function App the SQL connection string setting should be updated to follow this format:
         Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Database=testdb
      

    Refer the article Tutorial: Connect a function app to Azure SQL with managed identity and SQL bindings that provides more details on the above configurations. Please let us know if you still encounter the same issue after validating the above steps.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.