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();
}
}
and getting the following exception:
System.Data.SqlClient is not supported on this platform
Here are the chains of dependencies it's using:

How do I run a simple sql command from my app? What am I doing wrong?
If you don't need the latest stable version 4.6.0, simply revert to 4.5.1 would work.
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)\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- For local debug -->
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
There's an issue tracking this assembly reference problem.
I have downgrade the System.Data.SqlClient to 4.6.0 then it worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With