Reputation: 60691
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?
Upvotes: 15
Views: 10879
Reputation: 477
in my case i got resolved this by changing runtime version 3 to 2 under FunctionAppSettings in Azure's FunctionApp
Upvotes: 3
Reputation: 2385
I just ran into this with an Azure Functions instance that had somehow been configured to use .NET Core 3.0.0. I changed the configuration setting FUNCTIONS_EXTENSION_VERSION
from beta
to ~2
. After I restarted it, it went back to using 2.0.x and this error went away.
Upvotes: 3
Reputation: 164
I have downgrade the System.Data.SqlClient to 4.6.0 then it worked for me
Upvotes: 4
Reputation: 17790
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.
Upvotes: 21