runtime: Azure Functions - System.Data.SqlClient is not supported on this platform

Hi Team,

When using System.Data.SqlClient ( 4.6.0-preview-versions ) with azure functions, following exceptions is being thrown.

4.6.0-preview3-27014-02

System.Private.CoreLib: One or more errors occurred. (System.Data.SqlClient is not supported on this platform.). System.Data.SqlClient: System.Data.SqlClient is not supported on this platform

Downgrading the version to 4.5.1 works fine.

Tried with 2.2.100-preview2-009404 SDK too, still getting the same exception.

I am using the preview version because we need to use the AAD accesstoken property on SqlConnection Object.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 43 (11 by maintainers)

Most upvoted comments

Got the problem with 4.7.0 today. And the Microsoft.Data.SqlClient gives me the same error

This local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_V2_COMPATIBILITY_MODE": "true"
  }
}

and additional targets:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
[...]
  </ItemGroup>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
    <Exec Command="copy $(OutDir)local.settings.json $(OutDir)bin\local.settings.json" />
  </Target>
  <Target Name="PostPublish" BeforeTargets="Publish">
    <Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
  </Target>
</Project>

“fixed” this for me.

Same issue here: “System.Data.SqlClient” Version=“4.7.0”. Quite disappointing. We have been evaluating .Net Core, Azure functions for a large enterprise project. Strange issues with other .Net Core-based libraries as well. Things just look too flaky for a long term commitment.

@ryancole @danimal521 I downloaded 4.6.1 (prod release), the error is gone. Thanks for sharing the solution.

I can confirm. Downgrading to 4.6.1 resolved this issue for me as well.

@ryancole @danimal521 I downloaded 4.6.1 (prod release), the error is gone. Thanks for sharing the solution.

@ryancole that totally worked! I used 4.5.1 seemed to be the last prod build.

ss123

@danimal521 I was able to resolve the issue by downgrading the System.Data.SqlClient library by one release. It seems to have been in an issue in the release.

I’m using the latest (non-preview) version, but still the azure function is throwing the exception.

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" /> --> Has a dependency on 4.6.0

I assume it’s no longer preview ?

4.5.1 might “solve” (workaround) the issue as stated in the title. Reverting back form the 4.6 will result in the issue that one will not be able to use AAD auth ;

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1061	'SqlConnection' does not contain a definition for 'AccessToken' and no accessible extension method 'AccessToken' accepting a first argument of type 'SqlConnection' could be found (are you missing a using directive or an assembly reference?)

So using AAD auth towards Azure SQL is not possible in combination with Azure Functions…