I need to trigger a Winforms program that runs in taskbar tray whenever a row is added in SQL Server database from a web app. Is there a way to do this?
At the moment, the program runs all the time checking the database for new record and sleeps the underlying thread if nothing is inserted, but I need also to be able to trigger the program to run whenever a user inserted a row from a web app front-end.
added: web app, database, and winforms are running on the same one server.
thanks
"Standard" ways of triggering additional actions from inserts in SQL Server:
If the additional action is local to the database, and entirely implementable in transact SQL, the recommendation would be just to write it in a trigger.
If the additional action isn't implementable in transact SQL, then you might consider writing a CLR trigger. However, again I'd say that this is only appropriate if whatever is going to happen is local to the database.
If the additional action is appropriate to the server, but relies on e.g. other databases, or other features outside of the server, then you'd generally want to decouple the additional actions from the original INSERT operation. Two ways of dealing with this are SqlDependency, as others have said, or Service Broker.
If you're going the route of SqlDependency, you need something running permanently to use this object. This is what you'd typically put inside a windows service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With