SQL Server Automated Administration To automate administration: Establish the administrative responsibilities or server events that occur regularly and can be administered programmatically. Define a set of jobs and alerts. Run the SQL Server Agent service.
SQL Server Automated Administration Training Division New Delhi
SQL Server Agent Service SQL Server Agent supports features allowing the scheduling of periodic activities on Microsoft SQL Server, or the notification to system administrators of problems that have occurred with the server. The SQL Server Agent components that implement this capability are: Jobs Defined objects consisting of a one or more steps to be performed. The steps are Transact-SQL statements that can be executed. Jobs can be scheduled, for example, to execute at specific times or recurring intervals.
Alerts Operators Actions to be taken when specific events occur, such as a specific error, errors of certain severities, or a database reaching a defined limit of free space available. The alert can be defined to take such actions as sending an e-mail, paging an operator, or running a job to address the problem. People identified through their network account or e- mail ID who can address problems with the server. They can be the targets of alerts, either through e-mail, a pager, or a net send network command.
SQL Jobs
Job Name Every job must have a name. Job names must be unique only if they originate from the same server. A job name can be no more than 128 characters. Job Category Job categories allow you to organize your jobs for easy filtering and grouping.
Job Owner The job owner is the individual who creates a job or for whom the job is created. By default, SQL Server Agent populates the owner information with the SQL Server login ID of the job creator. Only members of the sysadmin role can give ownership of a job to another user or can alter the attributes of a job owned by another user.
Job Description A job can be run by other users on both the local and remote computers running SQL Server. By writing a description at the time a job is created, the job owner can ensure that other users will understand quickly the purpose of the job. A job description must not exceed 512 characters.
Implementing Jobs Administrative tasks can be automated using SQL Server Agent jobs. A job can be defined one time but can be run many times. A job can be manually or scheduled to run in response to schedules and alerts.
Jobs can be written to run on the local server or on multiple servers. To run jobs on multiple servers, you must set up at least one master server and one or more target servers. Anyone can create a job, but a job can be edited only by its owner or members of the sysadmin role.
Alerts
Are errors and messages, or events that are generated by SQL Server and entered into the Microsoft Windows NT application log. SQL Server Agent reads the application log and compares events to alerts that you have defined. When SQL Server Agent finds a match, it fires an alert.
Setting up a SQL Server database alert 1. On the View menu, click Alert. 2. On the Edit menu, click Add to Alert... 3. In the Object list, click a SQL Server object, and then click a counter, on which the alert will be based, from the Counter box. 4. Under Alert If, click Over or Under, and then enter a threshold value. The alert will be generated when the value for the counter is over or under the threshold value (depending on whether Over or Under was selected). 5. Click First Time or Every Time to determine how often the alert is generated. The default is Every Time.
SQL Mail
Allows SQL Server to send and receive e-mail by establishing a client connection with a mail server. SQL Server 7.0 uses two services to handle mail. SQL Mail. SQL Server Agent Mail. MS SQL Server processes mail for all of the mail stored procedures. SQL Server Agent uses its own mail capabilities that are configured and operated separately from SQL Mail.
SQL Mail establishes a simple MAPI connection with a mail host. SQL Agent Mail establishes either a simple or extended MAPI connection. Both SQL Mail and SQL Agent Mail can connect with MS Exchange Server, Windows NT Mail, or a POP3 server. SQL Mail stored procedures can manipulate data, process queries received by e-mail and return the result set by creating a reply e-mail. SQL Agent Mail can be configured to send an e-mail when an alert is triggered or when a scheduled task either succeeds or fails.
MAPI (Messaging Application Program Interface) is a Microsoft Windows program interface that enables 1. You to send e-mail from within a Windows application and attach the document you are working on to the e-mail note. 2. MAPI-compatible applications typically include a Send Mail or Send in the File pulldown menu of the application. This sends a request to a MAPI server. 3. MAPI consists of a standard set of C language functions that are stored in a program library known as a dynamic link library (DLL).
Developers who are using Microsoft's Active Server Page (ASP) technology access the MAPI library by using Microsoft's Collaboration Data Objects (CDO). The CDO library comes with Microsoft's Internet Information Server (IIS).
SQL Server and Mail Integration Microsoft SQL Server provides a set of extended stored procedures that allow SQL Server to operate as a workgroup post office for a MAPI-enabled e-mail system. The computer running SQL Server must be set up as an e- mail client. SQL Server Enterprise Manager is used to assign an e- mail account and password to the SQL Server installation. The mail component of SQL Server can then be enabled to be started automatically when the SQL Server Agent service is started. Alternatively, the mail component can be started and stopped at will using either SQL Server Enterprise Manager, or the xp_startmail, xp_stopmail, and xp_sendmail stored procedures.
When the mail component of SQL Server is running, it can be used to: Send e-mail from Transact-SQL batches, scripts, stored procedures, and triggers using xp_send_mail. The e-mail can be: Message strings. The result set of a query. A Transact-SQL statement or batch to execute. A page for an electronic pager.
E-mail can be read using: sp_processmail A combination of xp_findnextmessage xp_readmail, xp_deletemail.
The messages sent to SQL Server typically contain a Transact-SQL statement or batch to be executed. The statement is executed and the result set is returned as a reply e-mail with an optional CC: list. SQL Server events and alerts can be combined with SQL Mail functionality to build a system in which a server running SQL Server can e-mail or page the relevant administrators automatically if serious conditions arise.
Configuring a SQL Mail Profile When configured, mail profiles are specific to the Microsoft Windows NT user domain account that is activated when a user ogs on to Windows NT successfully. SQL Mail must have a mail profile created in the same user domain account or context that is used to start SQL Server. When a mail stored procedure is executed, SQL Mail looks for the defined mail profile in the domain account that triggered it. If you plan to use mail stored procedures you must: Have a mail server that is simple MAPI-compliant. Configure a mail profile for MSSQLServer to use to connect to your mail server.
How to configure a mail profile (Windows NT) To configure a mail profile 1. Logon to the Microsoft Windows NT server specifying the name and password used to start SQL Server services for that server. 2. Create and configure or copy an existing mail profile by clicking on the Mail icon in Control Panel. Select the appropriate mail service to interact with your mail host. Choose a name for the profile that will help the recipient identify the messages.
3. On the server running Microsoft SQL Server, start the mail client using the newly created mail profile. 4. Send a message addressed to the same profile name to ensure the mail client, mail profile, and e-mail provider are working properly. If your e-mail message does not appear, you may need to force mail synchronization by going to the Tools menu, and then clicking Deliver Now. 5. Exit the mail client program.
To set up SQL Mail How to set up SQL Mail (Enterprise Manager) 1. Expand a server group; then expand a server. 2. Click Support Services, right-click SQL Mail, and then click Properties. 3. In Profile name, select the mail profile that you configured for SQL Mail. 4. Click Test to check the systems ability to start and stop mail client services with the profile entered. You should receive a message that SQL Mail has started successfully and stopped a mail session with this profile.
Configuring a SQL Agent Mail Profile If you plan to send notifications to operators by e-mail or pager, you must: Have a mail server that is simple or extended MAPIcompliant. Configure a mail profile for SQL Server Agent to use to connect to your mail server. Have a mail server that is able to communicate with your pagers.
How to set the mail profile for SQL Server Agent (Enterprise Manager) To set the mail profile for SQL Server Agent 1. Right-click SQL Server Agent; then click Properties. 2. In the SQL Server Agent Properties dialog box, on the General tab, under Mail session, click a profile in the Mail profile box. If no profiles are listed, enter the name of the profile to use.
How to set up SQLAgentMail (Enterprise Manager) 1. Expand a server group; then expand a server. 2. Expand Management, right-click SQL Server Agent, and then click Properties. 3. If you have configured a mail profile using a different domain account than the one used to Microsoft SQL Server, click This Account, and then enter the Windows NT account name and password used to create the mail profile for SQLAgentMail. 4. In Mail profile, select the mail profile you created for SQLAgentMail. 5. Click Test to check the systems ability to start and stop mail client services with the profile entered. You should receive a message that SQL Mail has started successfully and stopped a mail session with this profile.
Sharing a Profile with SQL Mail SQL Mail and SQLAgentMail sessions may be configured to use the same Windows NT domain user account. When using the same domain account, SQL Mail and SQLAgentMail can share the same mail profile using a common mailbox. Microsoft SQL Server uses two separate mail sessions: The MSSQLServer service uses a mail session that is referred to as SQL Mail. SQL Server uses this mail session when your database applications execute the xp_sendmail extended stored procedure to send a message or query result set to a recipient. The SQLAgentMail uses a mail session that is exclusive to SQL Server Agent activities