Script to check status of database and mail to dba

  • Hello

    I would like to know a script to check if the database is running or not and mail it to the dba mail box.

    Thanks

     

  • One way I have done this is to check the status of the server by issueing a command like:

    xp_cmdshell 'sc \\yourservername query mssqlserver'

    You could then input the results into a table and absed on the result issue a xp_sendmail command.

  • Thanks for the command.

    Can you let me know , how to write the command for xp_sendmail.

    Thanks

  • Here is an example:

    IF EXISTS  (

       SELECT * FROM some_table WHERE value LIKE value  &nbsp

    BEGIN

    EXEC master..xp_sendmail @recipients = 'email_address',

        @message = 'email message',

        @copy_recipients = 'other_email',

        @subject = 'Subject Title'

    END

    GO

  • If checking for DB status, you may want to go that way:

    SELECT DATABASEPROPERTYEX ('YourDB','STATUS')

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply