Triggering a stored procedure in SQL Server 2005 by email - sql-server-2005

How can I trigger a stored procedure in SQL Server 2005 based on emails arriving in an Exchange inbox (with POP3/IMAP enabled)? I'd rather not use Windows Services if possible, and use the SQL Server functionality instead.

Exchange has Event Sinks which could write data to the DB.
Sample: http://www.codeproject.com/KB/cs/csmanagedeventsinkshooks.aspx
Doing thins using SQL Server somehow or a Windows Service would require polling for changes, which is less efficient; either you consume much resources through intensive polling or you have some delay until you notice a new message. The event sinks are basically invoked right away, and depending on the sink you can even influence the message.

Related

Socket programing/ Signaling changes in SQL Server

Is there any way to communicate with a socket using SQL language? (Why?) Assume that, I manually open SQL Server Management Studio and open a table and then insert a record manually (by manually I want to emphasize on the absence of any middleware in between). At this moment the business demands for signaling the inserted record to another context (as either notification, or report (i.e. grid view, etc)).
The solution that I have in mind is to write the inserted record to a file and using another application monitor the file for change (Emphasizing again that I don't wanna do this through a middleware at all) , but this method is not a standard way to achieve this requirement and it is more of a workaround.
Is there any standard way to signal changes using pure SQL Server syntax/features?
You can have a SQLCLR routine that calls out to "something", whenever a change happens. Where I work we ue that for real-time streaming of dats from SQL Server to RabbitMQ. In your case you would have to have a trigger on the table, which calls the routine.
In our case we always change data through stored procedures, so our procedures call the SQLCLR routine.
You could also use Service Broker and External Activation. In our case we chose not to do it as the performance was not good enough.
If you want, I have a blog-post about the SQL Server -> RabbitMQ integration using SQLCLR. Obviously it doesn't have to be Rabbit, we've also done it through socket connections etc. So if you're interested, the post is here.
Hope this helps!
Niels

Push data from MS SQL Server to Web Application

I have MS SQL Server 2012 Express on one end and a Node.JS web application on the other.
I need some way of tracking DML changes (insert, update or delete operations) to given tables.
Update Example:
If a record is updated, I need to send the updated record to my web application (could be a HTTP POST or write data over TCP)
The MS SQL Server is firewalled to prevent direct access nor would I want to poll the database.
How would I go about achieving this on the MS SQL Server end?
Consider posting to queues. Check out RabbitMQ. Node.js does have a rabbitmq client.
Post a message to the queue when a row is updated.
Make your node webapp listen to that queue.

Can my sql server send messages to activemq server without any java app in between

We are using Sql 2012 database server. When ever the db modifies we want it to trigger a message that can be stored in a queue using activemq.
We are not sure how can we code to trigger a db so that it sends a message.
Can we directly make the message generated from db to get queued in activemq without any java interface in between. I would want to know whether we can achieve this or not.
3.Are there any other ways to set up a communication between sql server and activemq say between database services and activemq services(does activemq have that)
PS i am a new user of activemq. Any leads to solve these queries is appreciated.
Please don't as SQL Server to do this. SQL Server is designed to store data. You are asking too much of it. Depending on how many places you would want to add to this queue from, I would choose one of the following solutions:
If you want to add to this queue from a bunch of different places, and don't want to change existing code, create an application to move items from SQL Server to ActiveMQ. The items in SQL Server can be populated by a trigger.
If there are only a few places that add to this queue, add that logic to the application so that every write to SQL Server will also write to ActiveMQ.
If you really still don't want to modify any code, you can configure ActiveMQ to use SQL Server as its persistence database. Then you can modify its data and hope that it plays nice. This is definitely not preferable. I would rather put CLR code into SQL Server to push data to ActiveMQ.

Notify my WCF service when my database is updated

I have a WCF service that needs to notify it's clients when changes occur to the database (sql server 2005). This is relatively easy accomplished, as long as I find a way to notify my service of any changes. I can probably create a database trigger on a table and have that trigger start a small service client that notifies my service, but I'm wondering if there's a better way to do this? It would be a viable solution to have the service poll the database for changes, but I'm not sure on the best way to do it (and sendign a notification to my service would be preferred).
As the relevant updates apply only to a certain part of the database, I was also wondering if it's also possible to link such a trigger (or other mechanism) to a database diagram.
All help is appreciated!
rinze
If your database is SQL Server 2005 and above you can try this solution: Remove pooling for data changes from a WCF front end.
As a side note, never call external processes from a trigger, don't make web calls from a trigger. Is a guaranteed recipe for disaster.
Update
For those interested in mixing Query Notifications with LINQ to SQL I recommend Using SQLDependency objects with LINQ.
Look at
SQL Server 2005 Query Notifications Tell .NET 2.0 Apps When Critical Data Changes
Change Notification with Sql Server 2008

Asynchronous Stored Procedure Calls

Is it possible to call a stored procedure from another stored procedure asynchronously?
Edit: Specifically I'm working with a DB2 database.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
Executive summary: Yes, if your database has a message queue service.
You can push a message onto a queue and the queue processor will consume it asynchronously.
Oracle: queues
Sql Server: service broker
DB2: event broker
For "pure" stored procedure languages (PL/Sql or T-Sql) the answer is no, since it works against the fundamental transaction model most databases have.
However, if your database has a queuing mechanism, you can use that to get the same result.
With MS Sql Server 2005, try the Service Broker and/or CLR stored procedures. I don't think there's anything built directly into TSQL.
It sounds like you need to put some scheduled jobs in place with Cron (or windows equiv). You could use the initial stored proc call to set some kind of flag in the DB, which is then checked periodically by a cron job. If you need to have a specific delay before the 2nd job executes, you should be able to do that by having the task scheduled by the cron job.