SQL Trigger (Change Event) to Azure Function

Viewed 1586

I read in this article that an Azure Function can be triggered by a trigger from CosmosDB. Can the same architecture be achieved with SQL DB? As an example, I add a row to a SQL DB table which will trigger an event which will invoke a Azure Function to run which will invoke a SignalR method.

1 Answers

Yes, you can!

But not directly with Azure Functions. Because there is no SQL Trigger for Azure Functions (yet?)

So how you can achieve this?

By the power of Logic Apps!

There is a built-in SQL Server connector and its triggers. Please see the screenshot below:

enter image description here

You can either choose when an item is created, or when an item is modified.

Let's say you wanted an item is created trigger. Next, you need to give the connection string of the database to the connector. Then it will prompt you to select which Table to listen. (In the example below, it will check the "Menus" table every 30 seconds.

enter image description here

Afterwards, when the condition is matched, you can set up an "Action" with Azure Functions (or any other action you want, such as send an email with Outlook) and pass any parameter you want from the table. In the example above, I chose one of my Azure Functions and chose the HeartBeat function, and passed the IsActive, DateCreated and AvailableTimeTo columns from the "Menus" table.

Hope it helps

Related