1. Trang chủ
  2. » Công Nghệ Thông Tin

Microsoft SQL Server 2005 Developer’s Guide- P48 pptx

10 219 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 242,93 KB

Nội dung

Chapter 12: Developing with SMO 449 To refer to the first database object by ordinal number, you use the following code: Dim oServerConn As ServerConnection = New ServerConnection() oServerConn.ServerInstance = "SQL2005" oServerConn.LoginSecure = True Dim oSQLServer As New Server(oServerConn) oSQLServer.Databases(0) Again, this code implicitly uses the Item method of the Databases collections. In this case, the Item method is passed the first ordinal value, instead of a string containing the name of the database. The ordinal value of 0 returns the first database in the oSQLServer object. Similarly, the ordinal value of 1 returns the second database, and so on. SMO Hierarchy The SMO object model extends and supplants its predecessor, the SQL-DMO object model. Unlike the SQL-DMO object framework, which was based on COM, the newer SMO object model is based on the .NET framework. This means that SMO requires the .NET framework to be installed on the systems that are used to run SMO management applications. SMO can be used to manage SQL Server 7 and SQL Server 2000, as well as SQL Server 2005, allowing you to easily manage a multiversion environment. SQL-DMO will also continue to be supported by SQL Server 2005, allowing backward compatibility for your applications, but SQL-DMO has not been enhanced to include the new features found in the new release. In other words, SQL-DMO is limited to supporting only those features that were found in the previous releases of SQL Server. The new SMO object framework contains over 150 new classes, enabling your custom management application to take advantage of the new features found in SQL Server 2005. The SMO object model consists of a hierarchy of objects contained in several namespaces and .dll files. The different SMO namespaces represent different areas of functionality within SMO. Table 12-2 lists the namespaces and their relative functionality. The core SMO namespace, Microsoft.SqlServer.Management.Smo, is implemented as a .NET assembly. This means that the Common Language Runtime (CLR) must be installed before using the SMO objects. The main SMO namespace contains classes that are divided into two categories: instance classes and utility classes. 450 Microsoft SQL Server 2005 Developer’s Guide Utility Classes The utility classes in SMO provide programmatic control over certain SQL Server objects and perform specific tasks, such as backup and restore, and transfer of schema and data. The utility classes are shown here: ᭤ Backup Provides programmatic access to SQL Server backup operations. ᭤ BackupDevice Provides programmatic access to SQL Server backup devices. ᭤ BackupDeviceItem Provides programmatic access to named SQL Server backup devices. ᭤ BackupRestoreBase A base class that represents functionality that is common to both backup and restore operations. ᭤ DatabaseActiveDirectory Provides programmatic access to the Active Directory settings for a database. ᭤ FullTextService Allows programmatic access to the Search Full Text settings. ᭤ PartitionFunction Provides programmatic access to partition functions. ᭤ PartitionFunctionParameter Provides programmatic access to partition function parameters. ᭤ PartitionScheme Provides programmatic access to partition schemes. ᭤ PartitionSchemeParameter Provides programmatic access to partition scheme parameters. Table 12-2 SMO Namespaces Namespace Function Microsoft.SqlServer.Management.Smo Contains instance classes, utility classes, and enumerations that are used to programmatically control SQL Server. Microsoft.SqlServer.Management.Common Contains the classes that are common to Replication Management Objects (RMO) and SMO. Microsoft.SqlServer.Management.Smo.Agent Contains classes that represent the SQL Server Agent. Microsoft.SqlServer.Management.Smo.Wmi Contains classes that represent the WMI Provider. Microsoft.SqlServer.Management.Smo.RegisteredServers Contains classes that represent Registered Server. Microsoft.SqlServer.Management.Smo.Mail Contains classes that represent Database Mail. Microsoft.SqlServer.Management.Smo.Broker Contains classes that represent the Service Broker. Microsoft.SqlServer.Management.Smo.NotificationServices Contains classes that represent Notification Services. Chapter 12: Developing with SMO 451 ᭤ ProgressReportEventArgs Provides programmatic access to the arguments used to report the progress of an operation that works through an object hierarchy, such as discovering dependencies in scripting operations. ᭤ Property Provides programmatic access to the properties of SMO objects. ᭤ Protocol Provides programmatic access to the protocols supported by SQL Server. ᭤ RelocateFile A programmatic tool that allows an .mdf or .ldf fi le to be relocated. ᭤ Restore Provides programmatic access to restore operations. ᭤ Rule Provides programmatic access to a SQL Server rule. ᭤ Scripter The overall, top-level object for managing scripting operations. ᭤ ScriptingErrorEventArgs Provides programmatic access to the arguments used to report the errors that occur during scripting operations. ᭤ ScriptingOptions Provides programmatic options to the options that can be set for scripting operations. ᭤ ServerActiveDirectory Provides programmatic access to Active Directory functionality. ᭤ ServerEventArgs Provides programmatic access to the arguments used to report all types of events that occur on an instance of SQL Server. ᭤ SmoEventArgs Provides programmatic access to the arguments used to report the events that occur in SMO applications. ᭤ SoapMethodCollectionBase A base class that is inherited by the SoapMethodCollection class and provides programmatic access to the collection of SOAP methods that exist in the SOAP confi guration. ᭤ SoapMethodObject A base class that is inherited by the SoapMethod class and provides programmatic access to the referenced SOAP method. ᭤ TcpProtocol Provides programmatic access to the protocols supported by SQL Server. ᭤ Transfer A tool object that provides programmatic control over copying of schemas and data to other instances of SQL Server. ᭤ Urn Provides programmatic access to Uniform Resource Name (URN) addresses that uniquely identify SQL Server objects. ᭤ VerifyCompleteEventArgs Provides programmatic access to the arguments used to report the details of the event that occurs when a backup verifi cation operation completes. 452 Microsoft SQL Server 2005 Developer’s Guide Instance Classes The instance classes embody SQL Server objects such as servers, databases, and tables and are organized into a hierarchical format. NOTE An important optimization that SMO has over SQL-DMO is called delayed instantiation. As your applications run, SMO retrieves the objects and properties only as they are needed. Unlike SQL-DMO, which gets everything up front, instead SMO makes many small round-trips to the server. SMO also lets you prefetch collections and retrieve objects using predefined properties. This lets you have control over SMO’s behavior as you build applications. SMO Server Object Hierarchy The Server object is the primary SMO object. The other SMO instance class objects reside under the Server object: ᭤ ActiveDirectory Returns a Microsoft.SqlServer.Management.Smo .ServerActiveDirectory object that specifi es the Active Directory settings for the database. ᭤ Confi guration Returns a Microsoft.SqlServer.Management.Smo.Confi guration object that specifi es the confi guration options for the instance of SQL Server. ᭤ ConnectionContext Returns Microsoft.SqlServer.Management.Common .ServerConnection object that specifi es the details of the current connection to the instance of SQL Server. ᭤ Events Returns a Microsoft.SqlServer.Management.Smo.ServerEvents object that represents the server events. ᭤ FullTextService Returns a Microsoft.SqlServer.Management.Smo .FullTextService object that specifi es the full-text service implementation on the instance of SQL Server. ᭤ Information Returns a Microsoft.SqlServer.Management.Smo.Information object that specifi es information about the instance of SQL Server. ᭤ JobServer Returns a Microsoft.SqlServer.Management.Smo.Agent.JobServer object that specifi es the SQL Server Agent associated with the instance of SQL Server. ᭤ ProxyAccount Returns a Microsoft.SqlServer.Management.Smo .ServerProxyAccount object that specifi es the proxy account associated with the instance of SQL Server. Chapter 12: Developing with SMO 453 ᭤ ServiceMasterKey Returns a Microsoft.SqlServer.Management.Smo .ServiceMasterKey object that specifi es the service master key associated with the instance of SQL Server. ᭤ Settings Returns a Microsoft.SqlServer.Management.Smo.Settings object that specifi es modifi able settings for the instance of SQL Server. ᭤ UserOptions Returns a Microsoft.SqlServer.Management.Smo.UserOptions object that specifi es user options for the current connection to the instance of SQL Server. NOTE This list only represents most of the objects in the SMO Server object hierarchy; the Server object collections are listed later in this section. Many of these objects also contain their own objects, properties, and collections. SMO Database Object Hierarchy The SMO Database objects let you work with the various SQL Server database objects such as defaults, rules, tables, and stored procedures. The following SMO objects and collections are contained in the SMO Database object hierarchy: Database Object Properties ᭤ ActiveDirectory Returns a Microsoft.SqlServer.Management.Smo .DatabaseActiveDirectory object that specifi es the Active Directory settings for the database. ᭤ CompatibilityLevel Returns a Microsoft.SqlServer.Management.Smo .CompatibilityLevel object value that specifi es the compatibility level of the database. ᭤ DatabaseOptions Returns a Microsoft.SqlServer.Management.Smo .DatabaseOptions object value that contains database confi guration options. ᭤ Events Returns a Microsoft.SqlServer.Management.Smo.DatabaseEvents object that represents the database events. ᭤ LogReuseWaitStatus Returns a Microsoft.SqlServer.Management.Smo .LogReuseWaitStatus that specifi es the type of operation on which the reuse of transaction log space is waiting. ᭤ MasterKey Returns a Microsoft.SqlServer.Management.Smo.MasterKey system object value that specifi es the master key used to encrypt the private keys of certifi cates. 454 Microsoft SQL Server 2005 Developer’s Guide ᭤ MirroringSafetyLevel Returns a Microsoft.SqlServer.Management.Smo .MirroringSafetyLevel object value that specifi es the mirroring safety level. ᭤ MirroringStatus Returns a Microsoft.SqlServer.Management.Smo .MirroringStatus object value that specifi es the status of the database and mirroring session. ᭤ MirroringWitnessStatus Returns a Microsoft.SqlServer.Management.Smo .MirroringWitnessStatus object value that specifi es the status of the mirroring witness server. ᭤ Parent Returns a Microsoft.SqlServer.Management.Smo.Server object that is the parent of the Microsoft.SqlServer.Management.Smo.Database object. ᭤ ReplicationOptions Returns a ReplicationOptions object value that specifi es the active replication settings for the database. ᭤ Status Returns a Microsoft.SqlServer.Management.Smo.DatabaseStatus object value that specifi es the status of the database. Database Collections ᭤ ApplicationRoles Returns a Microsoft.SqlServer.Management.Smo .ApplicationRoleCollection object that represents all the application roles defi ned on the database. ᭤ Assemblies Returns a Microsoft.SqlServer.Management.Smo .SqlAssemblyCollection object that represents all the assemblies defi ned on the database. ᭤ AsymmetricKeys Returns a Microsoft.SqlServer.Management.Smo .AsymmetricKeyCollection object that represents all the asymmetric keys defi ned on the database. ᭤ Certifi cates Returns a Microsoft.SqlServer.Management.Smo .Certifi cateCollection object that represents all the certifi cates defi ned on the database. ᭤ Defaults Returns a Microsoft.SqlServer.Management.Smo.DefaultCollection object that represents all the defaults defi ned on the database. ᭤ ExtendedProperties Returns a Microsoft.SqlServer.Management.Smo .ExtendedPropertyCollection object that specifi es the extended properties of the Microsoft.SqlServer.Management.Smo.Database object. ᭤ ExtendedStoredProcedures Returns a Microsoft.SqlServer.Management.Smo .ExtendedStoredProcedureCollection object that represents all the extended stored procedures defi ned on the database. Chapter 12: Developing with SMO 455 ᭤ FileGroups Returns a Microsoft.SqlServer.Management.Smo .FileGroupCollection object that represents all the fi legroups defi ned on the database. ᭤ FullTextCatalogs Returns a Microsoft.SqlServer.Management.Smo .FullTextCatalogCollection object that represents all the full-text catalogs defi ned on the database. ᭤ LogFiles Returns a Microsoft.SqlServer.Management.Smo.LogFileCollection object that represents all the log fi les defi ned on the database. ᭤ PartitionFunctions Returns a Microsoft.SqlServer.Management.Smo .PartitionFunctionCollection object that represents all the partition functions defi ned on the database. ᭤ PartitionSchemes Returns a Microsoft.SqlServer.Management.Smo .PartitionSchemeCollection object that represents all the partition schemes defi ned on the database. ᭤ Roles Returns a Microsoft.SqlServer.Management.Smo.DatabaseRoleCollection object that represents all the roles defi ned on the database. ᭤ Rules Returns a Microsoft.SqlServer.Management.Smo.RuleCollection object that represents all the rules defi ned on the database. ᭤ Schemas Returns a Microsoft.SqlServer.Management.Smo.SchemaCollection object that represents all the schemas defi ned on the database. ᭤ StoredProcedures Returns a Microsoft.SqlServer.Management.Smo .StoredProcedureCollection object that represents all the stored procedures defi ned on the database. ᭤ SymmetricKeys Returns a Microsoft.SqlServer.Management.Smo .SymmetricKeyCollection object that represents all the symmetric keys defi ned on the database. ᭤ Synonyms Returns a Microsoft.SqlServer.Management.Smo .SynonymCollection object that represents all the synonyms defi ned on the database. ᭤ Tables Returns a Microsoft.SqlServer.Management.Smo.TableCollection object that represents all the tables defi ned on the database. ᭤ Triggers Returns a Microsoft.SqlServer.Management.Smo.TriggerCollection object that represents all the triggers defi ned on the database. ᭤ UserDefi nedAggregates Returns a Microsoft.SqlServer.Management.Smo .UserDefi nedAggregateCollection object that represents all the user-defi ned aggregates defi ned on the database. 456 Microsoft SQL Server 2005 Developer’s Guide ᭤ UserDefi nedDataTypes Returns a Microsoft.SqlServer.Management.Smo .UserDefi nedDataTypeCollection object that represents all the user-defi ned data types on the database. ᭤ UserDefi nedFunctions Returns a Microsoft.SqlServer.Management.Smo .UserDefi nedFunctionCollection object that represents all the user-defi ned functions on the database. ᭤ UserDefi nedTypes Returns a Microsoft.SqlServer.Management.Smo .UserDefi nedTypeCollection object that represents all the user-defi ned types on the database. ᭤ Users Returns a Microsoft.SqlServer.Management.Smo.UserCollection object that represents all the users defi ned on the database. ᭤ Views Returns a Microsoft.SqlServer.Management.Smo.ViewCollection object that represents all the views defi ned on the database. ᭤ XmlSchemaCollections Returns a Microsoft.SqlServer.Management.Smo .XmlSchemaCollectionCollection object that represents all the XML schemas defi ned on the database. NOTE This list represents only some of the objects and collections in the SMO Database object hierarchy. Many of these objects also contain their own objects, properties, and collections. SMO Table Object and View Object Hierarchy The SMO Table and View objects let you drill down to the data level and work with the information on your SQL Server system. The following SMO objects and collections are contained in the SMO Table and View object hierarchy: Table Objects ᭤ Events Returns a Microsoft.SqlServer.Management.Smo.TableEvents object that represents the table events. ᭤ Parent Returns a Microsoft.SqlServer.Management.Smo.Database object value that is the parent of the Microsoft.SqlServer.Management.Smo.Table object. ᭤ Checks Returns a Microsoft.SqlServer.Management.Smo.CheckCollection object that represents all the check constraints defi ned on the table. Chapter 12: Developing with SMO 457 ᭤ ForeignKeys Returns a Microsoft.SqlServer.Management.Smo .ForeignKeyCollection object that represents all the foreign keys defi ned on the table. ᭤ PartitionSchemeParameters Returns a Microsoft.SqlServer.Management .Smo.PartitionSchemeParameterCollection object that represents all the partition scheme parameters defi ned on the table. View Objects ᭤ Events Returns a Microsoft.SqlServer.Management.Smo.ViewEvents object that represents the view events. ᭤ Parent Returns a Microsoft.SqlServer.Management.Smo.Database object value that specifi es the parent of the Microsoft.SqlServer.Management.Smo .View object. TableViewBase Objects ᭤ FullTextIndex Returns a Microsoft.SqlServer.Management.Smo .FullTextIndex object that represents a Microsoft Search full-text index. ᭤ Columns Returns a Microsoft.SqlServer.Management.Smo .ColumnCollection object that represents all the columns in the table. ᭤ ExtendedProperties Returns a Microsoft.SqlServer.Management.Smo .ExtendedPropertyCollection object that represents all the extended properties defi ned on the table or view. ᭤ Indexes Returns a Microsoft.SqlServer.Management.Smo.IndexCollection object that represents all the indexes defi ned on the table or view. ᭤ Statistics Returns a Microsoft.SqlServer.Management.Smo.StatisticCollection object that represents all the statistic counters defi ned on the table or view. ᭤ Triggers Returns a Microsoft.SqlServer.Management.Smo.TriggerCollection object that represents all the triggers defi ned on the table or view. SMO JobServer Object Hierarchy The SMO JobServer objects let you control SQL Servers Agent functions such as tasks, jobs, and alerts. The primary object of the SMO Agent objects is the JobServer object. The JobServer object controls SQL Server’s tasks and scheduling functions. 458 Microsoft SQL Server 2005 Developer’s Guide JobServer Object Properties ᭤ AgentLogLevel Returns a Microsoft.SqlServer.Management.Smo.Agent .AgentLogLevel object value that specifi es the type of messages that are logged by SQL Server Agent. ᭤ AlertSystem Returns a Microsoft.SqlServer.Management.Smo.Agent .AlertSystem object value that stores information about all the alerts defi ned on SQL Server Agent. ᭤ JobServerType Returns a Microsoft.SqlServer.Management.Smo.Agent .JobServerType object value that specifi es the type of job server. ᭤ Parent Returns a Microsoft.SqlServer.Management.Smo.Server object value that specifi es the parent of the Microsoft.SqlServer.Management.Smo.Agent .JobServer object. JobServer Collections ᭤ AlertCategories Returns a Microsoft.SqlServer.Management.Smo.Agent .AlertCategoryCollection object that represents all the alert categories defi ned on SQL Server Agent. ᭤ Alerts Returns a Microsoft.SqlServer.Management.Smo.Agent .AlertCollection that represents the alerts defi ned on SQL Server Agent. ᭤ JobCategories Returns a Microsoft.SqlServer.Management.Smo.Agent .JobCategoryCollection that represents the job categories defi ned on SQL Server Agent. ᭤ Jobs Returns a Microsoft.SqlServer.Management.Smo.Agent.JobCollection that represents the jobs defi ned on SQL Server Agent. ᭤ OperatorCategories Returns a Microsoft.SqlServer.Management.Smo .Agent.OperatorCategoryCollection that represents the operator categories defi ned on SQL Server Agent. ᭤ Operators Returns a Microsoft.SqlServer.Management.Smo.Agent .OperatorCollection that represents the operators defi ned on SQL Server Agent. ᭤ ProxyAccounts Returns a Microsoft.SqlServer.Management.Smo.Agent .ProxyAccountCollection that represents the proxy accounts defi ned on SQL Server Agent. ᭤ SharedSchedules Returns a Microsoft.SqlServer.Management.Smo.Agent .JobScheduleCollection that represents the shared schedules defi ned on SQL Server Agent. . code: Dim oServerConn As ServerConnection = New ServerConnection() oServerConn.ServerInstance = " ;SQL2 005" oServerConn.LoginSecure = True Dim oSQLServer As New Server( oServerConn) oSQLServer.Databases(0) Again,. manage SQL Server 7 and SQL Server 2000, as well as SQL Server 2005, allowing you to easily manage a multiversion environment. SQL- DMO will also continue to be supported by SQL Server 2005, . Returns a Microsoft. SqlServer.Management.Smo.Information object that specifi es information about the instance of SQL Server. ᭤ JobServer Returns a Microsoft. SqlServer.Management.Smo.Agent.JobServer

Ngày đăng: 05/07/2014, 05:20

TỪ KHÓA LIÊN QUAN