Azure Function can't connect to azure sql database


I'm trying to connect my azure function to my azure sql database. When trying it gives the following error.
Executed 'ClientID2' (Failed, Id=22ad8465-45f5-4fff-ba90-f0ff7d0ee465, Duration=5895ms)
[2021-11-25T10:49:57.575Z] System.Private.CoreLib: Exception while executing function: ClientID2. Microsoft.Data.SqlClient: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. Microsoft.Data.SqlClient: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

It runs on .net 5.0 framework, but not in .net core 3.1 .

        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log)
            string requestBody = string.Empty;
                log.LogInformation("Function process");

                using (SqlConnection connection = new SqlConnection(Environment.GetEnvironmentVariable("Connection_Database")))

 Packages installed:



Can anyone point me in the right direction?

Best regards

0 Replies