Share via

Send data from Azure SQL DB to IoT Hub

Kat_St 21 Reputation points
2021-01-05T00:20:19.99+00:00

Hello,
i'm a beginner in azure and i want to know is it possible to send data from Azure SQL DB to Iot Device? I configure Iot Hub, i send telemetry from device to SQL DB through Stream Analytics, but i also want to get data from database. I read about azure functions, but SQL DB isn't supported.
Any suggestions will be appreciated.

Azure SQL Database
Azure IoT Hub
Azure IoT Hub

An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.


Answer accepted by question author

Andriy Bilous 12,181 Reputation points MVP
2021-01-05T11:31:52.863+00:00

Hello @Kat_St
If you want just to query some data from Azure SQL DB and send a command to Iot Device, you can use Azure Function with Time Trigger(Runs every X minutes) or invoke it by HTTP request.
Azure Function supports SQL DB connection and can send messages to Iot Device using cloud-to-device messages, device-twins or direct-methods.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-scenario-database-table-cleanup?toc=/azure/azure-sql/toc.json
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-direct-methods

If you want to send a command to Iot Device when for example Table is modified in SQL Database you can use LogicApp + Function.
LogicApp can be triggered when Table in Azure SQL DB is created or modified.
LogicApp can invoke Azure Function with HTTP request.
https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-sqlazure?toc=/azure/azure-sql/toc.json
https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http

One more option is to use LogicApp together with IoT Central.
LogicApp is triggered when Table in Azure SQL DB is created or modified.
LogicApp can send command to Iot Device via IoT Central
https://learn.microsoft.com/en-us/azure/iot-central/core/howto-configure-rules-advanced

Was this answer helpful?

4 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.