DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: How to write a script which keep on checking database status?

  1. #1
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    182

    How to write a script which keep on checking database status?

    How to write a script which keep on checking database status(availability) once in a min at OS Level for Windows.

    Script should check service availability once a minute
    J Gangadhar

  2. #2
    Join Date
    Sep 2001
    Location
    Makati, Philippines
    Posts
    857
    use Task Scheduler, execute a batch file,
    and within a batch file, execute a script that test the availability of a server.

  3. #3
    Join Date
    Nov 2000
    Location
    Israel
    Posts
    268
    write a program, which will test the service status
    Code:
    // Open Service Manager
    m_schSCManager = OpenSCManager(lpMachineName, lpDatabaseName, dwDesiredAccess);
    
    // Open Specific Service
    schService = OpenService(
            m_schSCManager,
    	m_pService,
            dwDesiredAccess);
    
    // Query Service Status
    SERVICE_STATUS lServiceStatus;
    QueryServiceStatus(schService, &lServiceStatus);
    
    // get the status from the structure
    if (lServiceStatus.dwCurrentState == SERVICE_RUNNING)
            cout << "Service " << m_pService << " Is Running" << endl;
    else
    	cout << "Service " << m_pService << " Is Not Running" << endl;
    
    // Close Service and Manager
    CloseServiceHandle(schService);
    CloseServiceHandle(m_schSCManager);
    Write a thread that wakes up every minute and tests the service.

    Cheers,
    It is better to ask and appear ignorant, than to remain silent and remain ignorant.

    Oracle OCP DBA 9i,
    C++, Java developer

  4. #4
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    Oh, there's a lot more that can go wrong besides the service dying.

    Simplest is probably to run a SQL*Plus to read a row that you know should exist, spool this and do whatever you need to do with the output file.

    I started with this to do something more sophisticated: http://www.amazon.com/exec/obidos/tg...glance&s=books

  5. #5
    Join Date
    Feb 2001
    Posts
    295
    If there's budget, you can achieve much more sophisticated results on monitoring using software from IBM (Tivoli), Quest (Foglight) or Embarcadero.
    An ounce of action is worth a ton of theory.
    —Friedrich Engels

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width