Azure / Azure/azure-functions-host
SqlClient Errror in Azure app function V3 when launching in Docker with Visual Studio
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 36
Description
Getting the following error with Azure function V3.
```csharp
{System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
```
Please provide the following:
- Timestamp:
- Function App version: V3
- Function App name:
- Function name(s) (as appropriate):
- Invocation ID:
- Region:
#### Repro steps:
In Visual Studio, create a V3 Function with a Service Bus Trigger (the trigger should not matter), with docker support.
Add Entity Framework to the project
Add some code to query against a DB
Run the project locally in DEBUG config against Docker.
#### Workarounds
Run the project locally in RELEASE config against Docker
#### Related information
Here is the .csproj file for reference
```
netcoreapp3.1
v3
/home/site/wwwroot
Linux
PreserveNewest
```
Here is the docker file for reference
```
FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["dir/blah.csproj", "blah/"]
RUN dotnet restore "blah.csproj"
COPY . .
WORKDIR "/src/blah"
RUN dotnet build "blah.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "blah.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
```
Contributor guide
Assessment
This issue has not been assessed yet.