Azure 函数 - 此平台不支持 System.Data.SqlClient [英] Azure Function - System.Data.SqlClient is not supported on this platform
问题描述
我正在 azure 函数中将以下 insert
代码运行到 azure sql server 2014 数据库中:
I'm running the following insert
code within my azure function into an azure sql server 2014 database:
private static void Command(SqlConnection sqlConnection, string query)
{
var sqlCommand = new SqlCommand(query, sqlConnection);
try
{
sqlConnection.Open();
sqlCommand.ExecuteNonQuery();
}
finally
{
sqlConnection?.Close();
}
}
并得到以下异常:
此平台不支持 System.Data.SqlClient
System.Data.SqlClient is not supported on this platform
这是它使用的依赖链:
如何从我的应用程序运行一个简单的 sql 命令?我做错了什么?
推荐答案
如果你不需要最新的稳定版本 4.6.0
,只需恢复到 4.5.1
> 会工作.
If you don't need the latest stable version 4.6.0
, simply revert to 4.5.1
would work.
否则,解决方法是我们自己加载程序集.右键单击Function项目并Edit
,在下面添加项目以将相关程序集复制到输出目录.
Otherwise the workaround is to load the assemblies on our own. Right click on Function project and Edit <FunctionAppName>.csproj
, add items below to copy related assemblies to output dir.
<!-- For publish -->
<ItemGroup>
<None Include="$(USERPROFILE).nugetpackagessystem.data.sqlclient4.6.0
untimeswinlib
etcoreapp2.1System.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- For local debug -->
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE).nugetpackagessystem.data.sqlclient4.6.0
untimeswinlib
etcoreapp2.1System.Data.SqlClient.dll" DestinationFolder="$(OutputPath)in" />
</Target>
有一个问题跟踪这个程序集参考问题.
There's an issue tracking this assembly reference problem.
这篇关于Azure 函数 - 此平台不支持 System.Data.SqlClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!