Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « MongoDB: How to limit results and how to page through resultsMongoDB: How to include and exclude the fields you want in results »
    comments

    I have a bunch of SQL Agent jobs that execute T-SQL against databases. A bunch of these databases are mirrored. Of course if the database is the principal then these jobs will work without a problem. But what happens if you failover? Now these jobs will start failing. You can either have the same jobs on both servers and have them enabled or disabled depending where the mirror or principal is. You can very easy enable or disable these whenever you failover. For example

    1. USE msdb
    2. GO
    3.  
    4. UPDATE sysjobs
    5. SET enabled =1
    6. WHERE name IN ('',''....) --use a table that has all the jobs instead

    Or another way would be to check if the database is online to see if the job should continue running

    Here is such an example

    1. IF EXISTS(
    2. SELECT  1  FROM sys.databases
    3. WHERE state_desc = 'ONLINE'
    4. AND collation_name IS NOT NULL
    5. AND name = 'YourDB')
    6. BEGIN
    7. PRINT 'yep, good to go'
    8. END

    The reason we also check for collation_name in addition to state_desc is documented in Books On Line

    A database that has just come online is not necessarily ready to accept connections. To identify when a database can accept connections, query the collation_name column of sys.databases or the Collation property of DATABASEPROPERTYEX. The database can accept connections when the database collation returns a non-null value. For AlwaysOn databases, query the database_state or database_state_desc columns of sys.dm_hadr_database_replica_states.

    Yet another option would be to have a table with the 'live' server for the database, this however is more used for jobs, SSIS packages and programs that live on other servers

    How do you manage your jobs when dealing with mirroring? Leave me a comment, I am interested in your approach.

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    1765 views
    InstapaperVote on HN

    1 comment

    Comment from: NItin [Visitor]
    NItin Isnt it unsafe to update system table

    Id much rather play a safer bet of EXEC msdb.dbo.sp_update_job
    01/27/13 @ 04:51

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)