Azure functions: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

0

Trying to run this Azure Function in Azure portal but fails with above title error:

    using System;
    using System.IO;
    using System.Net;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Azure.WebJobs;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Logging;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    using System.Data.SqlClient;

    public static string Run(HttpRequest req, ILogger log)
    {
        string name="dbconn";
        string conStr = System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);

        if (string.IsNullOrEmpty(conStr)) // Azure Functions App Service naming convention
            conStr = System.Environment.GetEnvironmentVariable($"SQLCONNSTR_{name}", EnvironmentVariableTarget.Process);
        using (SqlConnection conn = new SqlConnection(conStr))
            {
                conn.Open();

            }
        return conStr;

I've added in the AzureSQL database ADO.NET ConnectionString: enter image description here Google search shows this issue mostly happening for local in regards to System.Data.SqlClient. But the issue I have is at host in azure's portal, i'm not publishing from VS, so not sure how to fix this. Help really appreciated.

In case I also tried to change System.Data.SqlClient for Microsoft.Data.SqlClient but can't compile: The type or namespace name 'Data' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

In Azure cli I can see .net core is v 2.2.402 and not sure if updating to 3.1 could this be the issue? I can update to .Net Core 3.1 on windows 10 pc but Azure cli continues to show .net core 2.2.402. I posted question in stackoverflow question how to also update the azure environment.

Thanks a bunch for your help, cheers!

azure
.net-core
azure-sql-database
azure-functions
asked on Stack Overflow Mar 4, 2020 by Sergio Solorzano • edited Mar 4, 2020 by Sergio Solorzano

1 Answer

1

It looks like something is wrong with the connection string. Please check that you are you using something similar to this:

Server=tcp:{your_server}.database.windows.net,1433;Initial Catalog={your_database};Persist Security Info=False;User ID={your_user};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

For what concern using Microsoft.Data.SqlClient, which is the recommended library, you need to add it to the solution first:

dotnet add package Microsoft.Net.SqlClient
answered on Stack Overflow Mar 4, 2020 by mauridb

User contributions licensed under CC BY-SA 3.0