[英]“sni.dll” not found while using System.Data.SqlClient using Azure C#
I'm trying to run a SELECT query from my sql server through an Azure Function App so I can later work on the data pulled from it.我正在尝试通过 Azure Z86408593C34AF77FDD90DF93 从我的 sql 服务器运行 SELECT 查询I'm fairly new to Azure so I might be missing something.
我对 Azure 还很陌生,所以我可能会遗漏一些东西。 My Runtime version is ~3.
我的运行时版本是 ~3。 It's a C# HTTP Trigger Function.
这是一个 C# HTTP 触发器 Function。
My code is based entirely on this blog entry https://randypaulo.com/2018/12/19/querying-azure-sql-database-using-azure-functions-2-0-to-return-json-data/我的代码完全基于此博客条目https://randypaulo.com/2018/12/19/querying-azure-sql-database-using-azure-functions-2-0-to-return-json-data/
This is the part where it breaks, at conn.Open();这是它中断的部分,在 conn.Open();
try
{
var str = Environment.GetEnvironmentVariable("sqldb_connection");
using(SqlConnection conn =new SqlConnection(str))
{
using(SqlCommand cmd =new SqlCommand())
{
SqlDataReader dataReader;
cmd.CommandText = "SELECT TOP 10 ID FROM CATALOG";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
dataReader = cmd.ExecuteReader();
var r = Serialize(dataReader);
json = JsonConvert.SerializeObject(r, Formatting.Indented);
}
}
}
The function compiles successfully with around 10+ warnings that look like this. function 编译成功,出现大约 10 多个类似这样的警告。
2021-02-01T21:54:58.159 [Warning] warning CS1701: Assuming assembly reference 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'System.Data.SqlClient' matches identity 'System.Data.Common, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Data.Common', you may need to supply runtime policy
However, when it comes to actually running the query, at the conn.Open();但是,当涉及到实际运行查询时,在 conn.Open(); line.
线。 I get a really long error message.
我收到一条很长的错误消息。 But it says "Unable to load DLL 'sni.dll' or one of its dependencies:"
但它说“无法加载 DLL 'sni.dll' 或其依赖项之一:”
2021-02-01T21:57:29.802 [Information] The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.
2021-02-01T21:57:29.803 [Information] System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception.---> System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)at System.Data.SqlClient.SNILoadHandle..ctor()at System.Data.SqlClient.SNILoadHandle..cctor()--- End of inner exception stack trace
I'm running on some limitations so I'm gonna list them out:我遇到了一些限制,所以我要列出它们:
Here is what I've tried so far这是我到目前为止尝试过的
What works:什么有效:
My questions:我的问题:
Is there a way to copy the sni.dll from the \shared\Microsoft.AspNetCore.App\2.2.14 folder to the \shared\Microsoft.AspNetCore.App\3.1.11 folder?有没有办法将 sni.dll 从 \shared\Microsoft.AspNetCore.App\2.2.14 文件夹复制到 \shared\Microsoft.AspNetCore.App\3.1.11 文件夹? (no success through the console, forbidden)
(通过控制台没有成功,禁止)
How can I reference/install custom or specific libraries through the Azure portal?如何通过 Azure 门户引用/安装自定义或特定库? (like #r "Newtonsoft.Json" or #load "file.csx")
(如 #r "Newtonsoft.Json" 或 #load "file.csx")
Do I need to mention the function.proj file I created in my run.csx file for it to work?我是否需要提及我在 run.csx 文件中创建的 function.proj 文件才能正常工作? How?
如何?
I manually switched the application setting "FUNCTION_EXTENSION_VERSION" to 2 instead of 3 .我手动将应用程序设置“FUNCTION_EXTENSION_VERSION”切换为2而不是3 。 Which changed the function Runtime version settings to ~2 .
这将 function 运行时版本设置更改为~2 。
And now the function is working correctly!现在 function 工作正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.