Azure Function can't connect to azure sql database

Copper Contributor

Hi.
I'm trying to connect my azure function to my azure sql database. When trying connection.open() 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=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

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

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

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

 Packages installed:

untitled.png

 

Can anyone point me in the right direction?

Best regards

0 Replies