Chapter 16. SQL Server Agent

SQL Server Agent automates administrative tasks by running jobs, monitoring SQL Server, and processing alerts.

You can define jobs and their schedules, alerts, and operators by using Object Explorer in SQL Server Management Studio, by using T-SQL scripts, or by using SQL Server Management Objects (SMO). Using SMO is the focus of this chapter.

SQL Server Agent is disabled by default. Start SQL Server Agent by connecting to a server instance in Object Explorer. Right-click the SQL Server Agent node and click Start on the context menu to start SQL Server Agent.

Set SQL Server Agent to start automatically by launching SQL Server Configuration Manager from Microsoft SQL Server 2005 → Configuration Tools. Select SQL Server 2005 Services in the left panel, right-click SQL Server Agent from the list of services in the right panel, and select Properties from the context menu to launch the SQL Server Agent Properties dialog box. Select the Service tab and change the Start Mode to Automatic.

Programming SQL Server Agent

Figure 16-1 shows the key SMO SQL Server Agent classes and defines the relationships between them.

These classes are in the Microsoft.SqlServer.Management.Smo.Agent namespace.

The rest of this chapter presents programming examples that show how to use SMO SQL Server Agent classes and provides descriptions of the classes. You need a reference to the following assemblies to compile and run the examples:

  • Microsoft.SqlServer.ConnectionInfo

  • Microsoft.SqlServer.Smo ...

Get Programming SQL Server 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.