180 likes | 267 Views
DBA Toolkit: Server Management Objects(SMO). Arie D. Jones Senior Microsoft Consultant Perpetual Technologies, Inc. February 21st, 2008. Speaker Background. Lead Microsoft Consultant for Perpetual Technologies 20+ years of programming experience 11 years of experience with SQL
E N D
DBA Toolkit: Server Management Objects(SMO) Arie D. Jones Senior Microsoft Consultant Perpetual Technologies, Inc. February 21st, 2008
Speaker Background • Lead Microsoft Consultant for Perpetual Technologies • 20+ years of programming experience • 11 years of experience with SQL • Lead author ‘SQL Functions’ book • Etc.
Server Management Objects • What is SMO? • Replacement of DMO • Used to program all aspects of managing a SQL Server. • SQL-DMO: COM based…Yuck! • SQL-SMO: .NET based….Yeah! • Compatible with 7.0, 2000, & 2005!
SMO .NET Classes • Root • Microsoft.SqlServer.Management.Smo • Agent • Broker • Mail • RegisteredServers • WMI Your logo here
So what can we do…. • Almost anything… • Create Databases • Script Objects • Create Jobs • Configure the SQL Server • Assign Permissions • Create Users Your logo here
Demo Time! • Hooking into the Server Your logo here
Server object • Things to remember • Default connection is Windows Authentication and Local instance • Windows authentication is based upon user or entity running the application • Server can be default or named instance • You can also search for the server • Remember to check which types these functions return! • Remember about explicitly calling Connect()! Your logo here
Server Object (cont.) • Remember that you need these references • Microsoft.SqlServer.Smo • Microsoft.SqlServer.SmoEnum • Microsoft.SqlServer.SqlEnum • Microsoft.SqlServer.ConnectionInfo Your logo here
Demo Time! • Creating and Manipulating Databases! Your logo here
Databases • Things to remember • Changes to the database structure are not automatically applied • You cannot simply drop items when iterating through a collection • Scripting can be performed even on non-existent objects Your logo here
Demo Time! • Managing Users and Security! Your logo here
Users and Security • Things to remember • Permissions are based upon ServerPermissionSets • Permissions can be enumerated by using ServerPermissionInfo object and EnumServerPermissions() Your logo here
Demo Time! • Creating and Managing Jobs Your logo here
Jobs • Things to remember • Imports Microsoft.SqlServer.Management.Smo.Agent • Schedules are separate from Jobs so don’t waste your time looking for the AddSchedule function. • JobServer are where jobs reside • TargetServer is where you deploy the job to Your logo here
Demo Time! • Backup and Restore Your logo here
Backup and Restore • Things to remember • Backups and Restores are separate from the the Server object • You must pass the Server object to the Backup or Restore command to tell it where to execute from • Make sure you know where you are at(database-wise) when you execute. Your logo here
Thank You! • Slides can be found on my blog • http://www.programmersedge.com • Or http://events.perptech.com • Email: arie.jones@perptech.com • Questions & Open Discussion • At least till they start wanting to hand out prizes!