Azure Iot Edge - System.Data.SqlClient is not supported on this platform

DataSciencentist2021 141 Reputation points
2021-12-08T10:25:41.233+00:00

Hi everyone,

I am currently trying to deploy a SQL Server module to store data on a device running Azure IoT Edge with Linux container following the official tutorial (https://learn.microsoft.com/en-us/azure/iot-edge/tutorial-store-data-sql-server?view=iotedge-2020-11).

Unfortunately there seem to be some problems regarding the SQL-connection:

1) The "sql"-module is up and running, but it says it is "disconnected":

155907-modules-deployed.png

2) It was possible to create the SQL-db and the table as described in the tutorial, but when I check the data in the table it is empty:

155897-empty-sql-db.png

So sqlFunction does not seem to be able to connect to the SQL-db.

3) When checking the "sqlFunction"'s Troubleshoot"-option in the Azure portal it says:

 [41m [30mfail [39m [22m [49m: Function.sqlFunction[3]  
      Executed 'sqlFunction' (Failed, Id=e83784d6-72e3-4312-a4b8-fce273256f20, Duration=158ms)  
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: sqlFunction  
 ---> System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.  
   at System.Data.SqlClient.SqlConnection..ctor(String connectionString)  
   at Functions.Samples.sqlFunction.FilterMessageAndSendMessage(Message messageReceived, IAsyncCollector`1 output, ILogger logger) in /app/sqlFunction.cs:line 36  
   at Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidTaskMethodInvoker.cs:line 20  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 572  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 518  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 296  
   --- End of inner exception stack trace ---  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 343  
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 105  

Until now, I already tried to fix the problem by doing the following:

  1. Added package reference ("<PackageReference Include="System.Data.SqlClient" Version="4.5.1"/>") in sqlFunction.csproj
  2. Added "System.Data.SqlClient" Version="4.5.1" via Nuget Package Manager in Visual Studio Code
  3. Changed the "sql"-module's image URI in deployment.template.json from "microsoft/mssql-server-linux:2017-latest" to "mcr.microsoft.com/mssql/server:2019-CU14-ubuntu-20.04"
  4. Added the ports needed to the UFW firewall on my Linux IoT Edge device. Also tried disabling the firewall completely.

So far nothing helped and I am running out of ideas. Could you please help me?

Best regards

Azure SQL Edge
Azure SQL Edge
An Azure service that provides a small-footprint, edge-optimized data engine with built-in artificial intelligence. Previously known as Azure SQL Database Edge.
45 questions
{count} vote

1 answer

Sort by: Most helpful
  1. DataSciencentist2021 141 Reputation points
    2021-12-20T09:59:41.583+00:00

    I just found a solution:
    Downgrading "System.Data.SqlClient" to version "4.1.0". (found on: https://stackoverflow.com/questions/49355530/system-data-sqlclient-is-not-supported-on-this-platform).

    Even though I think it would be better to user a newer version, I will now try to continue using "4.1.0".