intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Microsoft SQL Server 2005 Developer’s Guide- P48

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:10

44
lượt xem
2
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Microsoft SQL Server 2005 Developer’s Guide- P48:SQL Server 2005 is a feature-rich release that provides a host of new tools and technologies for the database developer. This book is written to help database developers and DBAs become productive immediately with the new features and capabilities found in SQL Server 2005.

Chủ đề:
Lưu

Nội dung Text: Microsoft SQL Server 2005 Developer’s Guide- P48

  1. 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.
  2. 450 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e 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. Table 12-2 SMO Namespaces 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.
  3. 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 file 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 configuration. 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 verification operation completes.
  4. 452 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e 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 specifies the Active Directory settings for the database. Configuration Returns a Microsoft.SqlServer.Management.Smo.Configuration object that specifies the configuration options for the instance of SQL Server. ConnectionContext Returns Microsoft.SqlServer.Management.Common .ServerConnection object that specifies 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 specifies the full-text service implementation on the instance of SQL Server. Information Returns a Microsoft.SqlServer.Management.Smo.Information object that specifies information about the instance of SQL Server. JobServer Returns a Microsoft.SqlServer.Management.Smo.Agent.JobServer object that specifies the SQL Server Agent associated with the instance of SQL Server. ProxyAccount Returns a Microsoft.SqlServer.Management.Smo .ServerProxyAccount object that specifies the proxy account associated with the instance of SQL Server.
  5. Chapter 12: Developing with SMO 453 ServiceMasterKey Returns a Microsoft.SqlServer.Management.Smo .ServiceMasterKey object that specifies the service master key associated with the instance of SQL Server. Settings Returns a Microsoft.SqlServer.Management.Smo.Settings object that specifies modifiable settings for the instance of SQL Server. UserOptions Returns a Microsoft.SqlServer.Management.Smo.UserOptions object that specifies 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 specifies the Active Directory settings for the database. CompatibilityLevel Returns a Microsoft.SqlServer.Management.Smo .CompatibilityLevel object value that specifies the compatibility level of the database. DatabaseOptions Returns a Microsoft.SqlServer.Management.Smo .DatabaseOptions object value that contains database configuration options. Events Returns a Microsoft.SqlServer.Management.Smo.DatabaseEvents object that represents the database events. LogReuseWaitStatus Returns a Microsoft.SqlServer.Management.Smo .LogReuseWaitStatus that specifies 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 specifies the master key used to encrypt the private keys of certificates.
  6. 454 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e MirroringSafetyLevel Returns a Microsoft.SqlServer.Management.Smo .MirroringSafetyLevel object value that specifies the mirroring safety level. MirroringStatus Returns a Microsoft.SqlServer.Management.Smo .MirroringStatus object value that specifies the status of the database and mirroring session. MirroringWitnessStatus Returns a Microsoft.SqlServer.Management.Smo .MirroringWitnessStatus object value that specifies 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 specifies the active replication settings for the database. Status Returns a Microsoft.SqlServer.Management.Smo.DatabaseStatus object value that specifies the status of the database. Database Collections ApplicationRoles Returns a Microsoft.SqlServer.Management.Smo .ApplicationRoleCollection object that represents all the application roles defined on the database. Assemblies Returns a Microsoft.SqlServer.Management.Smo .SqlAssemblyCollection object that represents all the assemblies defined on the database. AsymmetricKeys Returns a Microsoft.SqlServer.Management.Smo .AsymmetricKeyCollection object that represents all the asymmetric keys defined on the database. Certificates Returns a Microsoft.SqlServer.Management.Smo .CertificateCollection object that represents all the certificates defined on the database. Defaults Returns a Microsoft.SqlServer.Management.Smo.DefaultCollection object that represents all the defaults defined on the database. ExtendedProperties Returns a Microsoft.SqlServer.Management.Smo .ExtendedPropertyCollection object that specifies 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 defined on the database.
  7. Chapter 12: Developing with SMO 455 FileGroups Returns a Microsoft.SqlServer.Management.Smo .FileGroupCollection object that represents all the filegroups defined on the database. FullTextCatalogs Returns a Microsoft.SqlServer.Management.Smo .FullTextCatalogCollection object that represents all the full-text catalogs defined on the database. LogFiles Returns a Microsoft.SqlServer.Management.Smo.LogFileCollection object that represents all the log files defined on the database. PartitionFunctions Returns a Microsoft.SqlServer.Management.Smo .PartitionFunctionCollection object that represents all the partition functions defined on the database. PartitionSchemes Returns a Microsoft.SqlServer.Management.Smo .PartitionSchemeCollection object that represents all the partition schemes defined on the database. Roles Returns a Microsoft.SqlServer.Management.Smo.DatabaseRoleCollection object that represents all the roles defined on the database. Rules Returns a Microsoft.SqlServer.Management.Smo.RuleCollection object that represents all the rules defined on the database. Schemas Returns a Microsoft.SqlServer.Management.Smo.SchemaCollection object that represents all the schemas defined on the database. StoredProcedures Returns a Microsoft.SqlServer.Management.Smo .StoredProcedureCollection object that represents all the stored procedures defined on the database. SymmetricKeys Returns a Microsoft.SqlServer.Management.Smo .SymmetricKeyCollection object that represents all the symmetric keys defined on the database. Synonyms Returns a Microsoft.SqlServer.Management.Smo .SynonymCollection object that represents all the synonyms defined on the database. Tables Returns a Microsoft.SqlServer.Management.Smo.TableCollection object that represents all the tables defined on the database. Triggers Returns a Microsoft.SqlServer.Management.Smo.TriggerCollection object that represents all the triggers defined on the database. UserDefinedAggregates Returns a Microsoft.SqlServer.Management.Smo .UserDefinedAggregateCollection object that represents all the user-defined aggregates defined on the database.
  8. 456 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e UserDefinedDataTypes Returns a Microsoft.SqlServer.Management.Smo .UserDefinedDataTypeCollection object that represents all the user-defined data types on the database. UserDefinedFunctions Returns a Microsoft.SqlServer.Management.Smo .UserDefinedFunctionCollection object that represents all the user-defined functions on the database. UserDefinedTypes Returns a Microsoft.SqlServer.Management.Smo .UserDefinedTypeCollection object that represents all the user-defined types on the database. Users Returns a Microsoft.SqlServer.Management.Smo.UserCollection object that represents all the users defined on the database. Views Returns a Microsoft.SqlServer.Management.Smo.ViewCollection object that represents all the views defined on the database. XmlSchemaCollections Returns a Microsoft.SqlServer.Management.Smo .XmlSchemaCollectionCollection object that represents all the XML schemas defined 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 defined on the table.
  9. Chapter 12: Developing with SMO 457 ForeignKeys Returns a Microsoft.SqlServer.Management.Smo .ForeignKeyCollection object that represents all the foreign keys defined on the table. PartitionSchemeParameters Returns a Microsoft.SqlServer.Management .Smo.PartitionSchemeParameterCollection object that represents all the partition scheme parameters defined 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 specifies 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 defined on the table or view. Indexes Returns a Microsoft.SqlServer.Management.Smo.IndexCollection object that represents all the indexes defined on the table or view. Statistics Returns a Microsoft.SqlServer.Management.Smo.StatisticCollection object that represents all the statistic counters defined on the table or view. Triggers Returns a Microsoft.SqlServer.Management.Smo.TriggerCollection object that represents all the triggers defined 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.
  10. 458 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e JobServer Object Properties AgentLogLevel Returns a Microsoft.SqlServer.Management.Smo.Agent .AgentLogLevel object value that specifies 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 defined on SQL Server Agent. JobServerType Returns a Microsoft.SqlServer.Management.Smo.Agent .JobServerType object value that specifies the type of job server. Parent Returns a Microsoft.SqlServer.Management.Smo.Server object value that specifies 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 defined on SQL Server Agent. Alerts Returns a Microsoft.SqlServer.Management.Smo.Agent .AlertCollection that represents the alerts defined on SQL Server Agent. JobCategories Returns a Microsoft.SqlServer.Management.Smo.Agent .JobCategoryCollection that represents the job categories defined on SQL Server Agent. Jobs Returns a Microsoft.SqlServer.Management.Smo.Agent.JobCollection that represents the jobs defined on SQL Server Agent. OperatorCategories Returns a Microsoft.SqlServer.Management.Smo .Agent.OperatorCategoryCollection that represents the operator categories defined on SQL Server Agent. Operators Returns a Microsoft.SqlServer.Management.Smo.Agent .OperatorCollection that represents the operators defined on SQL Server Agent. ProxyAccounts Returns a Microsoft.SqlServer.Management.Smo.Agent .ProxyAccountCollection that represents the proxy accounts defined on SQL Server Agent. SharedSchedules Returns a Microsoft.SqlServer.Management.Smo.Agent .JobScheduleCollection that represents the shared schedules defined on SQL Server Agent.
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2