While the ACTIVITY table in the DYNAMICS database will tell you if a user is logged into Dynamics GP, you may find that the connection to SQL is lost. For this, we have to look at the Sysprocesses table in SQL.
A SQL select statement like the following will return the count of records for a specific user. If it is 0, then the user doesn’t have a valid session.
SELECT COUNT(*) FROM DYNAMICS..ACTIVITY AS ACT
INNER JOIN tempdb..DEX_SESSION AS SES ON (ACT.SQLSESID = SES.session_id)
INNER JOIN sys.sysprocesses AS PRC ON (SES.sqlsvr_spid = PRC.spid)
WHERE (ACT.USERID = ‘UserId’)
You can create a SQL Job and use Database Mail to notify you if the script returns 0 meaning it didn’t find a valid active session for GP with the login you are running SmartPost under.
Here is a sample of a script you can use with a SQL Job and Database Mail to do this. You will need to review the fields that need to be changed based on the comments in the script. This script is courtesy of David Joosten from Premier FMCG (Pty) Ltd.
BEGIN
/* This would be the mail recipient/s that you would like to send the mail to. Remember to separate recipients with a ; */
SET @textMailList = ‘someone@somedomain.com‘
/* This is the body of the message you would like to send. */
SELECT COUNT(*)
BEGIN
/* Send a mail to warn that the session is disconnected */
@recipients = @textMailList,
@body = @textMailMessage,
@body_format = ‘text’,
@subject = ‘SQL Automated Message’;
END;
As always, it is recommended that you make sure you review any scripts provided here and ensure they will be what you need before setting them up in your live environment.