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

标签 azure .net-core azure-sql-database azure-functions

尝试在 Azure 门户中运行此 Azure 函数,但失败并出现上述标题错误:

    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;

我在AzureSQL数据库中添加了ADO.NET ConnectionString: enter image description here Google 搜索显示此问题主要发生在本地 System.Data.SqlClient 中。但我遇到的问题是在 azure 门户的主机上,我不是从 VS 发布,所以不知道如何解决这个问题。非常感谢您的帮助。

如果我也尝试将 System.Data.SqlClient 更改为 Microsoft.Data.SqlClient 但无法编译:命名空间“Microsoft”中不存在类型或命名空间名称“Data”(您是否缺少程序集)引用?)

在 Azure cli 中,我可以看到 .net core 是 v 2.2.402,不确定更新到 3.1 是否会出现此问题?我可以在 Windows 10 电脑上更新到 .Net Core 3.1,但 Azure cli 继续显示 .net core 2.2.402。我在 stackoverflow 中发布了问题问题如何更新 azure 环境。

非常感谢您的帮助,干杯!

最佳答案

连接字符串似乎有问题。请检查您是否使用与此类似的东西:

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;

对于使用推荐库 Microsoft.Data.SqlClient 的问题,您需要先将其添加到解决方案中:

dotnet add package Microsoft.Net.SqlClient

关于Azure 函数 : Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60518486/

相关文章:

c# - 如何 `extern alias` 一个带有.Net核心的程序集?

azure - .NET Core 3.0 工作线程 - 无法使用 Application Insights 或 EventLog 进行日志记录

sql-server - Azure跨数据库查询、外部资源、外部表

Azure AD B2C,通过 Google Flutter 进行 Easy Auth 身份验证

azure - 无法从 Azure 文件共享读取文件

asp.net-mvc-4 - 同一台计算机上的两个 Chrome session - 一个将连接到我们的 Azure 网站,另一个 "unable to connect to SQL Server database"

ARM 嵌入式板的 C# .NET Core IoT 错误 : Unhandled exception. System.IO.IOException:设备或资源繁忙

azure-sql-database - 是否可以在 Azure SQL 数据库中配置查询超时?

sql-server - 如何设置 SQL Azure 报告?

azure - 什么是 Azure guest 操作系统?