w2olves
w2olves

Reputation: 2329

C# Azure Function trigger when SQL Database has a new row added without polling

Is there a way for an Azure function to be called every time a new database row is added to an SQL azure database ? Ideally without any timer based polling. I know this can be done on blob storage but dont see a way to do this on Azure function.

Thanks in advance

Upvotes: 11

Views: 19594

Answers (4)

user1843640
user1843640

Reputation: 3939

As of November 2022, Azure SQL trigger for functions is available (preview) for premium and dedicated plans. Unfortunately, it's not available for consumption plans.

Read about it here:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-sql-trigger

Upvotes: 1

Arithmomaniac
Arithmomaniac

Reputation: 4794

  1. Turn on Change Tracking in the SQL Database
  2. Use Azure Data Factory to write to Azure Table Storage
  3. Use that as a trigger for your funcion

ADF's documentation has a walkthrough for steps 1 and 2, except that they target Blob Storage (and reference Azure SQL throughout, except for a disclaimer at the top that it would also work with SQL Server).

Upvotes: 1

Cocowalla
Cocowalla

Reputation: 14331

Function Apps don't have an SQL trigger, but Logic Apps do, and it works for both on-premises SQL Server and Azure SQL Server. This will trigger when new rows are added, but do note it uses timer-based polling.

It

Upvotes: 8

Christian Melendez
Christian Melendez

Reputation: 376

It is possible but it's experimental right now. There's a guide that I'm putting at the end of this answer and you'll see that it's pretty straight forward. But again, this is experimental and don't expect that it works well all the time.

Another option will be in the code you have that insert a record to also send a message to queue o service bus and you can then make use of that as a trigger to your function (with service bus you also configure a dead letter queue for retries).

Reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-external-table

Upvotes: 4

Related Questions