TAILIEUCHUNG - Microsoft SQL Server 2005 Developer’s Guide- P23

Microsoft SQL Server 2005 Developer’s Guide- P23:This book is the successor to the SQL Server 2000 Developer’s Guide, which was extremely successful thanks to all of the supportive SQL Server developers who bought that edition of the book. Our first thanks go to all of the people who encouraged us to write another book about Microsoft’s incredible new relational database server: SQL Server 2005. | Chapter 12 Developing with SMO 459 TargetServerGroups Returns a . that represents the target server groups defined on SQL Server Agent. TargetServers Returns a .TargetServerCollection that represents the target server defined on SQL Server Agent. NOTE This list represents only the major objects in the SMO JobServer object hierarchy. Many of these objects also contain their own objects properties and collections. Building the SMO Sample Application In the first part of this chapter you had an overview of SMO objects followed by an explanation of some of the most important SMO collections methods and properties. In the next part of the chapter you learn how you can put SMO to work in a sample program. Figure 12-3 presents the main screen of an example SMO application name that was built using . Figure 12-3 A sample SMO application 460 Microsoft SQL Server 2005 Developer s Guide This sample application demonstrates many of the essential techniques required to use SMO including Creating the Server object Connecting to a SQL Server system Using collections Getting specific objects from a collection Creating new database objects Copying existing database objects Disconnecting from a SQL Server system The sample application lists the registered SQL Server systems in a drop-down box enabling the user to select the desired system to connect to. After selecting the desired SQL Server system the user selects the appropriate authentication type. If SQL Server Authentication is selected then the user is prompted to enter the Login ID and Password. If Windows Authentication is chosen the user simply clicks the Connect button. Following a successful connection the sample application lists all the databases the user is authorized to use. Lists showing the tables and columns for the first database in the list are filled in automatically. The