Link to home
Start Free TrialLog in
Avatar of LarryDAH
LarryDAHFlag for United States of America

asked on

User SQL database mail to send warning

Occassionally we have a service on a SQL stop; I have database mail working, at least I can send a test message to myself. Is there some way to use it to send an email when a server does not start after reboot or stops during the day?
Avatar of dba2dba
dba2dba

Run this as a DOS Script. Schedule this as reuired or add as a startup script if needed.

------------------------------------------------------
@ECHO OFF
IF EXIST (SC query IISAdmin | FIND "STATE" | FIND "RUNNING")
sqlcmd
'
EXEC msdb.dbo.sp_send_dbmail ................

'
----------------------------------------------------------
Replace IISAdmin with the service name of interest. (Please note the actual service name in the properties and not go by name of service in services console)

Write appropriate dbmail command to send a message to you.

Thanks,
Avatar of LarryDAH

ASKER

The server I am interested in for th SQL server, so I changed IISAdmin to MSSQLServer. Using info at http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/ I created a SQL query that sends and email to me when executed, but how would I tie it all together. If the SQL service stops under Recovery you can restart the service, restart the server, etc or execute a program. How would I get it to run my dbmail query?
Look at this link.  It describes out to execute a procedure on SQL Server startup.

http://msdn.microsoft.com/en-us/library/ms181720.aspx
Avatar of Anthony Perkins
>>How would I get it to run my dbmail query?<<
If there is no SQL Service then you cannot using database mail.
In this case, you can use some windows mailers.... BMAIL is one of them.

http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm

Thanks,

The part you are overlooking is in bold:
"How would I get it to run my dbmail query?"
No application or utility can be used to retrieve a query if there is no SQL Server service. Period.
That makes sense, if the SQL service is stopped it will not send a query off to tell us that. WHat about using an Event ID trigger. How can I figure out what event id a stopped SQL service would be?
I am afraid I have no idea.
ASKER CERTIFIED SOLUTION
Avatar of LarryDAH
LarryDAH
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial