Take the 2-minute tour ×

Do to some constraints with a client's system and setup, I am wondering if it is possible for SQL Server to fire off a web request?

I need to be able to send emails after a sql server column gets updated. I had a trigger with database mail but the database server on the client won't allow that. The alternative would have that figure fire off a web request when ready. I would do it via a web service on the web server and have it just poll the table, but that seems like a lot of wasteful cycles.

Any ideas?

share|improve this question
Hi - That's a question I've asked myself many times over many versions (I've been with MSSQL since 6.5) ... and, last time I checked, "polling" was still the best answer :( I'm hopeful that .Net integration might be a good solution in newer versions of MSSQL. But I assure you, firing off COM/ActiveX objects from a SQL trigger definitely wasn't (in MSSQL2000 or lower) :( –  paulsm4 Sep 25 '12 at 0:19
THat kinda sucks, I'm looking into SQL CLR Web requests now –  chris Sep 25 '12 at 0:21
I'm running 2005. –  chris Sep 25 '12 at 0:22
I'm definitely curious if CLR works for you. It should - and I'm hoping it does :) –  paulsm4 Sep 25 '12 at 0:24
I used a SQL CLR to fire a web request, then the web server sent the email –  chris Sep 26 '12 at 0:03
add comment

2 Answers

up vote 2 down vote accepted

You can execute managed code from SQL server. Create a windows service and let that do whatever you want in C# to fulful your need and SQL server call it.

Checkout this link for sample program

share|improve this answer
add comment

Do not call web services from SQLCLR, and especially do not call web services (or send email) via SQLCRL from triggers. There are many reasons why using SQLCLR for external http or smtp access is a bad idea, but doing it from a trigger is horrendous. Just think how will your application behave in a day when the web service responds with a 10 second latency...

You must do the mail interaction from an external application. You should decouple the interaction between your application and the emailer application via a queue. See Using Tables as Queues for how to use a SQL Server table as a queue. You can enqueue the mailing request directly from your application, or use a stored proc that both inserts the data and enqueue the request, or as the last resort, use a trigger on the table to enqueue the mailing request. You emailer application (a separate service) should monitor this queue and service it by doing the actual email send (or http web request , for the matter).

share|improve this answer
add comment

Your Answer


