Enable immediate processing
With the SMS Server you can send messages by just inserting new records into the database. Do this by using any of the ‘Insert..’ views documented here.
After inserting the message it sends out automatically. The time between inserting and sending depends on the poll time (‘Outgoing interval‘) configured in the server options.
This page describes a way to force the SMS Server to send out the message immediately after inserting.
NOTE: This does not apply when sending messages from SQL triggers. These always send immediately.
Requirements
This method only works if:
- The database is installed on the same server as the SMS Server;
- The database server runs the SMS Server client configuration type.
Database settings
This uses the notification API from the local API so we’ll need to enable OLE (ActiveX / COM).
Find out more about the notification API and the notification broker in the introduction about immediate processing and sending.
Enable OLE in your database by running these commands in the SMS Server database:
USE SmsServer -- Change to the SMS Server database name
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Stored procedure
Next you’ll need a new stored procedure called: ‘usp_NotifyStatusUpdate’.
You can create this by running the following script on your database.
USE SmsServer -- Change to the SMS Server database name
GO
/*
Call 'NotifyStatusUpdate' on the MessageDB object.
*/
CREATE PROCEDURE usp_NotifyStatusUpdate
AS
BEGIN
DECLARE @hr INT
DECLARE @objMessageDB INT
DECLARE @src VARCHAR(255), @desc VARCHAR(255);
EXECUTE @hr = sp_OACreate 'AxMmServer.MessageDB', @objMessageDB OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objMessageDB, @src OUT, @desc OUT
RAISERROR('Error Creating AxMmServer.MessageDB 0x%x, %s, %s',16,1, @hr, @src, @desc)
RETURN
END
EXECUTE @hr = sp_OAMethod @objMessageDB, 'NotifyStatusUpdate', NULL, ''
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objMessageDB, @src OUT, @desc OUT
RAISERROR('Error Calling NotifyStatusUpdate 0x%x, %s, %s',16,1, @hr, @src, @desc)
RETURN
END
EXECUTE sp_OADestroy @objMessageDB
END
GO
You can use this stored procedure to force processing of new message. This cause any new messages to be send immediately.
How to use
Simply execute:
EXECUTE SmsServer.dbo.usp_NotifyStatusUpdate
This sends a push to the SMS Server to pickup any new messages.
If you’re inserting a batch of new messages makes sure to only call this stored procedure once right after creating the batch.
We don’t recommend calling this stored procedure from an insert table trigger.