21
1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation [email protected] Session Code: DAT360

1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

1

Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview

Bruce PrangDevelopment ManagerMicrosoft [email protected]

Session Code: DAT360

Page 2: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

2

What is SMOWhat is SMO

SQL Server Management ObjectsProgrammatic object model for DDL operationsUse it for creation, management, discovery, configuration of Sql Servers.NET Class LibraryNot a total abstraction of Sql Server

SQL Server Management ObjectsProgrammatic object model for DDL operationsUse it for creation, management, discovery, configuration of Sql Servers.NET Class LibraryNot a total abstraction of Sql Server

Page 3: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

3

Some of the Design GoalsSome of the Design Goals

100% coverage of Sql Server featuresImprove scalability and performanceSimple to use, but rich object modelHigh level of control over object model behaviorAdvanced scripting capabilitiesBuild SQL Server Workbench on it

100% coverage of Sql Server featuresImprove scalability and performanceSimple to use, but rich object modelHigh level of control over object model behaviorAdvanced scripting capabilitiesBuild SQL Server Workbench on it

Page 4: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

4

Object ModelObject Model

DatabasesDatabases

ServerServer

ConnectionContextConnectionContext

DatabaseDatabase

SqlAssemblySqlAssembly

FileGroupFileGroup

TablesTables

TableTable

AssembliesAssemblies

FileGroupsFileGroups

JobServerJobServer

JobsJobs

JobJob

AlertsAlerts

AlertsAlerts

Shared SchedulesShared Schedules

Job ScheduleJob Schedule

Page 5: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

5

SMO – lets see it

Ovidiu [email protected] Server Management Tools

Page 6: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

6

SMO

SMO ArchitectureSMO Architecture

Utility Utility ClassesClasses

Instance Instance ClassesClasses

Scripter Scripter ClassesClasses

Management ApplicationManagement Application

WMI WMI ProviderProvider

Enumeration Enumeration ComponentComponent

Connection ClassConnection Class (SQL Server .NET Data Provider)(SQL Server .NET Data Provider)

SQL ServerSQL ServerConfigure/EnumConfigure/Enum

Page 7: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

7

SMO FeaturesSMO Features

Optimized instantiation of objectsScripting – Basic and AdvancedCapture of Transact-SQLSupport for new Yukon featuresUse of .NET types

E.g. DateTime, Timespan instead of scaled long integers, etc.

Management Object Model for SQL Services and Configuration (through WMI Provider)

Optimized instantiation of objectsScripting – Basic and AdvancedCapture of Transact-SQLSupport for new Yukon featuresUse of .NET types

E.g. DateTime, Timespan instead of scaled long integers, etc.

Management Object Model for SQL Services and Configuration (through WMI Provider)

Page 8: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

8

Feature OverviewOptimized InstantiationFeature OverviewOptimized Instantiation

Instance Classes support “optimized (delayed) instantiation”

Object states 1: Partially instantiated (some properties available)2: Fully instantiated

Full instantiation is triggered when a property is called that has not been retrieved yet, or when a method is called that requires a missing property

Instance Classes support “optimized (delayed) instantiation”

Object states 1: Partially instantiated (some properties available)2: Fully instantiated

Full instantiation is triggered when a property is called that has not been retrieved yet, or when a method is called that requires a missing property

Page 9: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

9

Feature OverviewOptimized InstantiationFeature OverviewOptimized Instantiation

Can be controlled by programmerDefaultInitFields, PrefetchObjects

Fits any scenario

Can be controlled by programmerDefaultInitFields, PrefetchObjects

Fits any scenario

Memory optimalMemory optimal Network/Query optimalNetwork/Query optimal

Delayed Delayed instantiation instantiation

per object per object [default][default]

Many Many objects objects

fully fully initializedinitialized

Page 10: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

10

SMO – lets tune it

Ovidiu [email protected] Server Management Tools

Page 11: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

11

Feature OverviewCapture ModeFeature OverviewCapture Mode

All Transact-SQL generated by performing actions on SMO objects can be captured or recorded

This is NOT transactional, it is only capture

WorkBench Dialogs use this capability to script operations

All Transact-SQL generated by performing actions on SMO objects can be captured or recorded

This is NOT transactional, it is only capture

WorkBench Dialogs use this capability to script operations

Page 12: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

12

Feature OverviewScripter ClassFeature OverviewScripter Class

Basic ScriptingAll DMO Scripting options will continue to be supportedScript interface on individual classes will also be available (same as SQL-DMO)

Advanced ScriptingFiltering, available in multiple placesList modificationObject modificationProgress and Error events

Basic ScriptingAll DMO Scripting options will continue to be supportedScript interface on individual classes will also be available (same as SQL-DMO)

Advanced ScriptingFiltering, available in multiple placesList modificationObject modificationProgress and Error events

Page 13: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

13

Scripting PhasesScripting Phases

/****** Object: Table [employee] Script Date: 9/28/2001 4:02:31 PM ******/if not exists (select * from dbo.sysobjects where id = object_id(N'[employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)BEGINCREATE TABLE [employee](

[emp_id] [empid] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[fname] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[minit] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS,

[lname] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[job_id] [smallint] NOT NULL CONSTRAINT [DF__employee__job_id__1B0907CE] DEFAULT (1)

Single phase without manipulation

Page 14: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

14

Scripting PhasesScripting Phases

ListGeneration

ScriptGeneration

ManipulationDiscovery Manipulation

/****** Object: Table [employee] Script Date: 9/28/2001 4:02:31 PM ******/if not exists (select * from dbo.sysobjects where id = object_id(N'[employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)BEGINCREATE TABLE [employee](

[emp_id] [empid] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[fname] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[minit] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS,

[lname] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[job_id] [smallint] NOT NULL CONSTRAINT [DF__employee__job_id__1B0907CE] DEFAULT (1)

Page 15: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

15

How Did We Get Here?How Did We Get Here?

SQL Server 6.x – SQLOLESQL Server 7.0 – SQL-DMOSQL Server 2000 – SQL-DMOSQL Server Yukon– SMO

Architectural limitations in DMONeeded a .Net class libraryNeeded Full Support in object model

SQL Server 6.x – SQLOLESQL Server 7.0 – SQL-DMOSQL Server 2000 – SQL-DMOSQL Server Yukon– SMO

Architectural limitations in DMONeeded a .Net class libraryNeeded Full Support in object model

Page 16: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

16

Backwards CompatibleBackwards Compatible

SMO SupportsSQL Server 7.0SQL Server 2000SQL Server “Yukon”COM callable wrappers for Script

DMO “Yukon”Shipping in the Yukon boxWorks against “Yukon”No new Yukon features

SMO SupportsSQL Server 7.0SQL Server 2000SQL Server “Yukon”COM callable wrappers for Script

DMO “Yukon”Shipping in the Yukon boxWorks against “Yukon”No new Yukon features

Page 17: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

17

SMO – a little more

Ovidiu [email protected] Server Management Tools

Page 18: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

18

SQL Server ResourcesSQL Server ResourcesWeek long SQL Server “Ask the Experts” lounge in:

Foyer outside Room 309

Support for SQL Server “Yukon” PDC Preview at SQLJunkieshttp://www.sqljunkies.com/forums

SQL Server “Yukon” FAQ Blog at SQLTeamhttp://yukonblog.sqlteam.com/

Other Key Resourceshttp://www.microsoft.com/sql/communityhttp://msdn.microsoft.com/sqlserver/34 world wide user groups,

http://msdn.microsoft.com/usergroups/find.asp

Our most active SQL Server newsgroups,Microsoft.public.sqlserver.programmingMicrosoft.public.sqlserver.serverMicrosoft.public.sqlserver.dtsMicrosoft.public.sqlserver.olapMicrosoft.public.sqlserver.setupMicrosoft.public.sqlserver.replicationMicrosoft.public.sqlserver.msde

Week long SQL Server “Ask the Experts” lounge in: Foyer outside Room 309

Support for SQL Server “Yukon” PDC Preview at SQLJunkieshttp://www.sqljunkies.com/forums

SQL Server “Yukon” FAQ Blog at SQLTeamhttp://yukonblog.sqlteam.com/

Other Key Resourceshttp://www.microsoft.com/sql/communityhttp://msdn.microsoft.com/sqlserver/34 world wide user groups,

http://msdn.microsoft.com/usergroups/find.asp

Our most active SQL Server newsgroups,Microsoft.public.sqlserver.programmingMicrosoft.public.sqlserver.serverMicrosoft.public.sqlserver.dtsMicrosoft.public.sqlserver.olapMicrosoft.public.sqlserver.setupMicrosoft.public.sqlserver.replicationMicrosoft.public.sqlserver.msde

Page 20: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation

20© 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Page 21: 1 Building Management Applications with SQL Server “Yukon” SQL Management Objects (SMO): Overview Bruce Prang Development Manager Microsoft Corporation