【问题标题】:Azure functions: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)Azure 函数:无法加载 DLL“sni.dll”或其依赖项之一:找不到指定的模块。 (0x8007007E)
【发布时间】:2020-06-16 11:58:06
【问题描述】:

尝试在 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: 谷歌搜索显示这个问题主要发生在本地关于 System.Data.SqlClient。但是我遇到的问题是在 azure 门户中的主机上,我不是从 VS 发布的,所以不知道如何解决这个问题。非常感谢您的帮助。

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

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

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

【问题讨论】:

  • 你的函数是从 vs 部署的吗?

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


【解决方案1】:

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

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 SQL 和 Azure Function 的完整工作示例在这里:github.com/yorek/azure-sql-hyperscale-autoscaler
  • 感谢@mauridb,是的,连接字符串符合您在上面显示的模式。关于 dotnet 命令,我在 Azure cli 中执行并得到错误在/home/sergio/ 中找不到任何项目。然后我尝试了 kudu 的功能 CMD D:\home\site\wwwroot>cd FunctionName 和 D:\home\site\wwwroot 但仍然在“路径”中找不到任何项目。我可能做错了什么?
  • 我尝试了您发布的 git 示例,直接部署到门户出现错误当前的 .NET SDK 不支持定位 .NET Core 3.1。以 .NET Core 2.2 或更低版本为目标,或者使用支持 .NET Core 3.1 的 .NET SDK 版本。 [D:\home\site\repository\Autoscaler.csproj] 。但是我的 dotnet --info 显示 .NET Core SDK(反映任何 global.json):版本:2.2.402。只能从VS运行?
  • 非常感谢@mauridb,我已经使用了您的项目设置,现在可以避免此错误消息。我还发现您链接的项目对 sql 例程非常有帮助:)
  • 确保 Azure 函数应用程序设置中有“AzureSQLConnection”
猜你喜欢
  • 1970-01-01
  • 2014-12-04
  • 2023-02-22
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-05
  • 2012-02-18
  • 2018-10-26
相关资源
最近更新 更多