<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Michiel Wories' WebLog : SMO Samples</title><link>http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx</link><description>Tags: SMO Samples</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>SMO Samples Galore</title><link>http://blogs.msdn.com/mwories/archive/2005/10/25/smo-samples-galore.aspx</link><pubDate>Tue, 25 Oct 2005 19:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:484717</guid><dc:creator>mwories</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mwories/comments/484717.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=484717</wfw:commentRss><description>&lt;P&gt;With much of the SQL Server 2005 devcelopment behind us, I am starting to have some more time &lt;a href="http://blogs.msdn.com/mwories/articles/category/11245.aspx"&gt;to post some SMO samples&lt;/A&gt;. Most of these are inspired on questions in the beta newsgroups or the &lt;A href="http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=88"&gt;SMO/DMO forum&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Additionally, SQL Server 2005 ships with a pretty wide variety of samples. In fact, there are more SMO samples than there are for any other product area, and we have been adding samples up till a a few weeks ago (from here it is pretty much locked down).&lt;/P&gt;
&lt;P&gt;Let me know if you have any sample requests!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=484717" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item><item><title>SQL Server: Table Partitioning in SQL Server 2005</title><link>http://blogs.msdn.com/mwories/archive/2005/06/24/table-partitioning-sample.aspx</link><pubDate>Fri, 24 Jun 2005 22:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432333</guid><dc:creator>mwories</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mwories/comments/432333.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=432333</wfw:commentRss><description>&lt;DIV&gt;Table and Index partitioning is one if the new SQL Server 2005 features that willl improve life for the DBA and application developer quite a bit. It allows Indexes and Tables to be partitioned across multiple file groups. Partitioned tables and indexes, are fully manageable with SMO. Here is a quick sample to get you started, with not too much explanation as speaks for itself, mostly. Let me know if you have questions!&lt;/DIV&gt;
&lt;DIV&gt;&lt;BR&gt;Server svr = new Server();&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Database db = new Database(svr, "MyDatabase");&lt;BR&gt;db.FileGroups.Add(new FileGroup(db, "PRIMARY"));&lt;BR&gt;db.FileGroups.Add(new FileGroup(db, "SECONDARY"));&lt;BR&gt;db.FileGroups[0].Files.Add(new DataFile(db.FileGroups[0], "datafile1", @"c:\db1.mdf"));&lt;BR&gt;db.FileGroups[1].Files.Add(new DataFile(db.FileGroups[1], "datafile2", @"c:\db2.mdf"));&lt;BR&gt;db.Create();&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;PartitionFunction pf = new PartitionFunction(db, "MyPartitionFunction");&lt;BR&gt;pf.PartitionFunctionParameters.Add(new PartitionFunctionParameter(pf, DataType.Int));&lt;BR&gt;pf.RangeType = RangeType.Left;&lt;BR&gt;pf.RangeValues = new object[] { 5000 };&lt;BR&gt;pf.Create();&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;PartitionScheme ps = new PartitionScheme(db, "MyPartitionScheme");&lt;BR&gt;ps.PartitionFunction = "MyPartitionFunction";&lt;BR&gt;ps.FileGroups.Add("PRIMARY");&lt;BR&gt;ps.FileGroups.Add("SECONDARY");&lt;BR&gt;ps.Create();&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Table t = new Table(db, "MyTable");&lt;BR&gt;t.Columns.Add(new Column(t, "c1", DataType.Int));&lt;BR&gt;t.Columns.Add(new Column(t, "c2", DataType.VarChar(100)));&lt;BR&gt;t.PartitionScheme = "MyPartitionScheme";&lt;BR&gt;t.PartitionSchemeParameters.Add(new PartitionSchemeParameter(t, "c1"));&lt;BR&gt;t.Create();&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;// Script out the objects (for educational purposes; optional) &lt;BR&gt;SqlSmoObject[] objs = new SqlSmoObject[4];&lt;BR&gt;objs[0] = db;&lt;BR&gt;objs[1] = pf;&lt;BR&gt;objs[2] = ps;&lt;BR&gt;objs[3] = t;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;for (int i = 0; i &amp;lt; 4; i++)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("-- " + objs[i].ToString());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (string s in ((IScriptable)(objs[i])).Script())&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(s);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("GO");&lt;BR&gt;}&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;IMG src="http://www.mseventseurope.com/teched/05/pre/content/banners/images/signatures/teched-speak-s-150.gif" border=0&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=432333" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item><item><title>SQL Server: Capture Object changes with SMO Capture Mode</title><link>http://blogs.msdn.com/mwories/archive/2005/05/31/capture-mode.aspx</link><pubDate>Wed, 01 Jun 2005 00:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:423575</guid><dc:creator>mwories</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mwories/comments/423575.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=423575</wfw:commentRss><description>&lt;P class=MsoNormal&gt;In a previous article I have showed how a SMO object can be serialized into a Transact-SQL script, which allows you to recreate the object. What if you want to have the script that is emitted when you changed one or more properties of an object? In that case Capture Mode comes in handy. This switches the ServerConnection object in a state where it starts capturing all statements that SMO emits instead of sending these to the server. The following sample illustrates how it is used.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=MsoNormal&gt;Server svr = new Server();&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;Database db = svr.Databases["MySmoTestDatabase"];&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// First create new test database, if it does not exist&lt;BR&gt;if (db == null)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; db = new Database(svr, "MySmoTestDatabase");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.Create();&lt;BR&gt;}&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Set an option (we flip it to on or off depending orginal state)&lt;BR&gt;db.DatabaseOptions.AutoClose = !db.DatabaseOptions.AutoClose;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Switch SMO in capture mode&lt;BR&gt;svr.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Now perform the operation&lt;BR&gt;db.Alter();&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Don't forget to switch back&lt;BR&gt;svr.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Put database back in original state&lt;BR&gt;db.Refresh();&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;// Print script&lt;BR&gt;foreach (string s in svr.ConnectionContext.CapturedSql.Text)&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(s);&lt;BR&gt;}&lt;/PRE&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;Note the Refresh() near the end. This is needed to bring back the Database object in sync with the server again. It’s not enough to execute the script (if you would do that) to bring it in sync with the server.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;

&lt;img border="0" src="http://www.mseventseurope.com/teched/05/pre/content/banners/images/signatures/teched-speak-s-150.gif"&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=423575" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item><item><title>SQL Server: SMO Scripting Basics</title><link>http://blogs.msdn.com/mwories/archive/2005/05/07/basic-scripting.aspx</link><pubDate>Sat, 07 May 2005 21:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:415398</guid><dc:creator>mwories</dc:creator><slash:comments>52</slash:comments><comments>http://blogs.msdn.com/mwories/comments/415398.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=415398</wfw:commentRss><description>&lt;P class=MsoNormal&gt;Let's first clarify what I mean by "scripting". It often happens during talks or when I explain SMO fundamentals that eyes gloss over, shortly after which the "what * do you mean by scripting" question pops up (replace the * with your favorite combination of&amp;nbsp;adjective and noun to indicate bewilderment). For people who, unlike me, do not live their lives in SQL land, "scripting" means&amp;nbsp;typically some kind of language script, like perl, VBScript, or others, that allows you, without the use of a development environment to author and execute code". Not so in this case. If I were to be precise, it means "serialize a SMO or DMO object into Transact-SQL". So now we have this out of the way, let's take a look at SMO Scripting.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;SMO objects, when either just instantiated and not yet persisted, or just retrieved from the server, carry state. For example a StoredProcedure object has a name, a schema, a text body, and maybe some other optional properties. This state can be serialized into a Transact-SQL script that you may store, modify, or execute. As SQL Server’s primary language is Transact-SQL, it’s obvious that one of the tasks that the SMO object model has to perform very well is scripting. SMO objects can be scripted in 5 different ways:&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI class=MsoNormal&gt;By calling the &lt;B&gt;Script()&lt;/B&gt; method on the object. 
&lt;LI class=MsoNormal&gt;By instantiating a &lt;B&gt;Scripter object&lt;/B&gt;, and pass in a reference of the object(s) to be scripted. 
&lt;LI class=MsoNormal&gt;Advanced scripting: &lt;B&gt;generating a script in 3 distinct phases&lt;/B&gt; (discovery, list, script) 
&lt;LI class=MsoNormal&gt;By using the &lt;B&gt;Transfer object&lt;/B&gt;. 
&lt;LI class=MsoNormal&gt;Indirectly, by &lt;B&gt;capturing the SQL output&lt;/B&gt; of the objects&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;I will discuss 1 and 2 and will dedicate some more posts on the other more advanced topics.&lt;/P&gt;
&lt;H3&gt;&lt;A name=_Toc102900547&gt;Basic Scripting&lt;/A&gt;&lt;/H3&gt;
&lt;P class=MsoNormal&gt;Let’s start with scripting an existing object, with no options specified (installing AdventureWorks will help running these samples):&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; svr.Databases[&lt;SPAN&gt;"AdventureWorks"&lt;/SPAN&gt;].StoredProcedures[&lt;SPAN&gt;"uspGetEmployeeManagers"&lt;/SPAN&gt;, &lt;SPAN&gt;"dbo"&lt;/SPAN&gt;].Script())&lt;BR&gt;{&lt;BR&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;.WriteLine(s);&lt;BR&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;If you run this code, the script should be emitted to the console. So far pretty straightforward eh?&lt;/P&gt;
&lt;H3&gt;Scripting Options&lt;/H3&gt;
&lt;P&gt;If you want to do more than just scripting the object, there are scripting options that you can pass into the Script() method. There 2 ways to pass in Scripting options. The following 2 samples illustrate the different methods of passing in scripting options.&lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;StoredProcedure&lt;/SPAN&gt;&lt;SPAN&gt; sp = svr.Databases[&lt;SPAN&gt;"AdventureWorks"&lt;/SPAN&gt;].StoredProcedures[&lt;SPAN&gt;"uspGetEmployeeManagers"&lt;/SPAN&gt;, &lt;SPAN&gt;"dbo"&lt;/SPAN&gt;];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;ScriptingOptions&lt;/SPAN&gt;&lt;SPAN&gt; so = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;ScriptingOptions&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;so.IncludeHeaders = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;so.SchemaQualify = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; sp.Script(so))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;&lt;SPAN&gt;.WriteLine(s);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;In the next sample, you use the ScriptOption class. This class has various static members that each return an instance of a ScriptionOption class.&lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;StoredProcedure&lt;/SPAN&gt;&lt;SPAN&gt; sp = svr.Databases[&lt;SPAN&gt;"AdventureWorks"&lt;/SPAN&gt;].StoredProcedures[&lt;SPAN&gt;"uspGetEmployeeManagers"&lt;/SPAN&gt;, &lt;SPAN&gt;"dbo"&lt;/SPAN&gt;];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; sp.Script(&lt;SPAN&gt;ScriptOption&lt;/SPAN&gt;.IncludeHeaders + &lt;SPAN&gt;ScriptOption&lt;/SPAN&gt;.SchemaQualify))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;&lt;SPAN&gt;.WriteLine(s);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;You can take advantage of the fact that the ScriptOption static members returns a ScriptingOption class (through &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfimplicit.asp"&gt;implict conversion&lt;/A&gt;), as you can use it as an alternative to construct a Scriptingoption class:&lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;ScriptingOptions&lt;/SPAN&gt;&lt;SPAN&gt; so = &lt;SPAN&gt;ScriptOption&lt;/SPAN&gt;.IncludeHeaders;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;so.SchemaQualify = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;H3&gt;Script modified objects&lt;/H3&gt;
&lt;P class=MsoNormal&gt;You can modify and script an object, without persisting its state. This sample shows how this can be accomplished:&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;StoredProcedure&lt;/SPAN&gt; sp = svr.Databases[&lt;SPAN&gt;"AdventureWorks"&lt;/SPAN&gt;].StoredProcedures[&lt;SPAN&gt;"uspGetEmployeeManagers"&lt;/SPAN&gt;, &lt;SPAN&gt;"dbo"&lt;/SPAN&gt;];&lt;BR&gt;&lt;BR&gt;sp.TextHeader = &lt;SPAN&gt;"-- Scripted at "&lt;/SPAN&gt; + &lt;SPAN&gt;DateTime&lt;/SPAN&gt;.Now.ToString() + &lt;SPAN&gt;"\n\n"&lt;/SPAN&gt; + sp.TextHeader;&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; sp.Script())&lt;BR&gt;{&lt;BR&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;.WriteLine(s);&lt;BR&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;Ensure that you either call the Refresh() method on the object once you are done, or persist the object by calling Alter(), as this temporary state may cause problems when this object is referenced again for other purposes.&lt;/P&gt;
&lt;H3&gt;Script non-existing objects&lt;/H3&gt;
&lt;P&gt;Alternative, you can instantiate a new object, and emit the script for it, without requiring it to exist on the server. In fact the below script will not even connect to the server; this happens all on your client. &lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;Database&lt;/SPAN&gt; db = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Database&lt;/SPAN&gt;(svr, &lt;SPAN&gt;"MyDatabase"&lt;/SPAN&gt;);&lt;BR&gt;&lt;BR&gt;db.DatabaseOptions.AutoClose = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; db.Script())&lt;BR&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;&lt;SPAN&gt;.WriteLine(s);&lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;H3&gt;Using the Scripter object&lt;/H3&gt;
&lt;P&gt;If you call the Script() method on an object, what actually happens, is that in the background a Scripter() object is instantiated, which performs the various scripting operations. Whereas each object knows how to emit script, the Scripter object pulls it all together, and does special processing before or while generating the output. Let’s take a look how the Scripter object can be used to accomplish the same task as above (scripting a database). &lt;/P&gt;
&lt;TABLE class=MsoTableGrid cellSpacing=0 cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;Server&lt;/SPAN&gt;&lt;SPAN&gt; svr = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Server&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;Database&lt;/SPAN&gt;&lt;SPAN&gt; db = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Database&lt;/SPAN&gt;(svr, &lt;SPAN&gt;"MyDatabase"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;db.DatabaseOptions.AutoClose = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;Scripter&lt;/SPAN&gt;&lt;SPAN&gt; scripter = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Scripter&lt;/SPAN&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;scripter.Server = svr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;scripter.Options.IncludeHeaders = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;scripter.Options.SchemaQualify = &lt;SPAN&gt;true&lt;/SPAN&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;SqlSmoObject&lt;/SPAN&gt;&lt;SPAN&gt;[] objs = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;SqlSmoObject&lt;/SPAN&gt;[1];&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;objs[0] = db;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;scripter.Script(objs);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;foreach&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;SPAN&gt;string&lt;/SPAN&gt; s &lt;SPAN&gt;in&lt;/SPAN&gt; scripter.Script(objs))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=MsoNormal&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console&lt;/SPAN&gt;&lt;SPAN&gt;.WriteLine(s);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;The above samples I have touched on the basis of the scripting operations. In the next posts I will elaborate and show you more complex and elaborate ways to generate script. We made scripting extremely flexible, and hope that this first post helps you to get started with scripting.&lt;/P&gt;&lt;SPAN&gt;Enjoy!&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=415398" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item><item><title>SQL Server: Tuning your SMO Application for great performance -- PART 2</title><link>http://blogs.msdn.com/mwories/archive/2005/05/02/smoperf2.aspx</link><pubDate>Mon, 02 May 2005 11:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:413906</guid><dc:creator>mwories</dc:creator><slash:comments>53</slash:comments><comments>http://blogs.msdn.com/mwories/comments/413906.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=413906</wfw:commentRss><description>&lt;P class=MsoNormal&gt;In the previous post I provided you with a fundamental tool to minimize the amount of SQL statements emitted and therefore limit expensive network round-trips (and SQL statements) using the &lt;B&gt;Server.SetDefaultInitFields()&lt;/B&gt; method. In this post I will provide you with some more detail about this method, alongside with a recommendation about its use.&lt;BR&gt;&lt;BR&gt;Let's take a quick look at the optimized sample that I provided last article:&lt;BR&gt;&lt;BR&gt;&lt;SPAN&gt;&lt;BR&gt;Server svr = new Server();&lt;BR&gt;&lt;BR&gt;Database db = svr.Databases["AdventureWorks"];&lt;BR&gt;&lt;B&gt;svr.SetDefaultInitFields(typeof(Table), "CreateDate");&lt;/B&gt;&lt;BR&gt;foreach (Table t in db.Tables)&lt;BR&gt;{&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);&lt;BR&gt;}&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;This optimization is particular to this piece of code,&amp;nbsp;but the setting is global to the Server instance so every time you will retrieve a Table object later in your code, it will load the same fields as just specified. It's recommended to save the state of the previous SetDefaultInitFields setting so you can set it to the same value after you have retrieved your objects. The following sample shows you have to save the state, and then set if back to that state:&lt;BR&gt;&lt;SPAN&gt;&lt;BR&gt;Server svr = new Server();&lt;BR&gt;&lt;BR&gt;Database db = svr.Databases["AdventureWorks"];&lt;BR&gt;&lt;BR&gt;&lt;B&gt;StringCollection sc = svr.GetDefaultInitFields(typeof(Table));&lt;/B&gt;&lt;BR&gt;&lt;BR&gt;svr.SetDefaultInitFields(typeof(Table), "CreateDate");&lt;BR&gt;foreach (Table t in db.Tables)&lt;BR&gt;{&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);&lt;BR&gt;}&lt;BR&gt;&lt;B&gt;svr.SetDefaultInitFields(typeof(Table), sc);&lt;/B&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;The reason you want to be careful with this is that the SetDefaultInitFields setting is global to the Server object reference, and you are likely to hold on to the Server object instance reference (svr in the above example) to perform additional work with it. For example, if you were to call Refresh() on the Tables collection, any additional operation that would cause a table object to be instantiated in the collection will use the latest SetDefaultInitFields setting.&lt;BR&gt;&lt;BR&gt;SetDefaultInitFields has a few more helpful overloads that I will describe here:&lt;/P&gt;
&lt;TABLE class=MsoNormalTable cellPadding=0&gt;

&lt;TR&gt;
&lt;TD&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;SetDefaultInitFields(System.Type typeObject, System.Boolean allFields)&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;Specifies all properties are fetched when the specified object is instantiated. When set to false, the fields will be reset to default.&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;SetDefaultInitFields(System.Boolean allFields)&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;Specifies all properties are fetched when &lt;B&gt;any&lt;/B&gt; object is instantiated. When set to false, the fields will be reset to default..&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&lt;SPAN&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Recommendation: make sure your application is aware of this global Server state, and either specifically set the fields or reset to the previous value. If you do not take care about this, you may see sudden application degradation (or your customers may start to notice), and as it will be very hard to test all code paths you cannot know beforehand how your application is going to behave in the future if· this is not carefully managed. Also, if you pass the Server reference on to another library that component may change the field settings and cause 'mysterious' performance degradation that may be hard to debug.&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=413906" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item><item><title>SQL Server: Tuning your SMO Application for great performance - PART 1 (featured at TechED)</title><link>http://blogs.msdn.com/mwories/archive/2005/04/22/smoperf1.aspx</link><pubDate>Fri, 22 Apr 2005 23:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:410875</guid><dc:creator>mwories</dc:creator><slash:comments>37</slash:comments><comments>http://blogs.msdn.com/mwories/comments/410875.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mwories/commentrss.aspx?PostID=410875</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial color=#000000&gt;I'm ramping up for TechED 2005 (Both USA and Europe) and will be giving a couple of talks on SMO. This is a repost of an article from SqlJunkies, as I am still moving these blog entries to MSDN. Ping&lt;/FONT&gt;&lt;FONT face=Arial color=#000000&gt;&amp;nbsp;me if you are visiting TechED and are interested in certain SMO topics.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;HR&gt;

&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Unlike SQL-DMO, &lt;FONT color=#0000ff&gt;SQL Server Management Objects (SMO)&lt;/FONT&gt; gives you a fairly fine level of control how data is retrieved from the server.&lt;BR&gt;&lt;BR&gt;When using default behavior, an SMO object transitions into the following states:&lt;BR&gt;&lt;BR&gt;1. Partially instantiated -- some properties are available (such as Name, Schema)&lt;BR&gt;2. Fully instantiated -- all low cost properties are retrieved in bulk when you retrieve any of these&lt;BR&gt;3. Expensive properties -- are fetched when needed, one at the time (such as database space)&lt;BR&gt;&lt;BR&gt;The rationale behind this is to allow the object model to scale when a high number of objects need to be retrieved, for example when populating a collection of 10,000 tables. In contrast, SQL-DMO always fetches all properties when populating a collection. This can be compared with doing a 'select * from xxx', when you only want to know something about name and the creation date of the object. SMO fetches only the minimal set of properties that are required to populate the collection (i.e. for Table, Name and Schema are needed to uniquely identify the object).&lt;BR&gt;&lt;BR&gt;Now here comes the catch: if your application does fetch extra properties, besides the minimally required ones, it will submit a query to retrieve these extra properties. This can cause your application to become extremely 'chatty', and will likely cause it to perform not as good (or just bluntly bad). This is especially noticed when doing 'foreach' enumerations, such as shown in the example below:&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#000080&gt;Server svr = new Server();&lt;BR&gt;&lt;BR&gt;Database db = svr.Databases["AdventureWorks"];&lt;BR&gt;foreach (Table t in db.Tables)&lt;BR&gt;{&lt;BR&gt;Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);&lt;BR&gt;}&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;You can inspect the result by switching SQL Profiler on and looking at the number of batches that are emitted to SQL Server.&lt;BR&gt;&lt;BR&gt;When running above sample you will find about 155 rows in the SQL Profiler. The application is certainly chattier than it should be. This app's performance is especially down the drain on networks with a higher latency than a typical LAN, but even on a LAN it does not perform very well.&lt;BR&gt;&lt;BR&gt;Enter &lt;B&gt;Server.SetDefaultInitFields()&lt;/B&gt;. This call allows you to set the fields that are retrieved when the object gets initialized. This would add one extra line to the above sample:&lt;BR&gt;&lt;FONT color=#000080&gt;&lt;BR&gt;Server svr = new Server();&lt;BR&gt;&lt;BR&gt;Database db = svr.Databases["AdventureWorks"];&lt;BR&gt;&lt;B&gt;svr.SetDefaultInitFields(typeof(Table), "CreateDate");&lt;/B&gt;&lt;BR&gt;foreach (Table t in db.Tables)&lt;BR&gt;{&lt;BR&gt;Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);&lt;BR&gt;}&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;Note that you do not have to indicate any of fields that are retrieved by default (Name, Schema).&lt;BR&gt;&lt;BR&gt;After running the above sample, you will find &lt;B&gt;only 11&lt;/B&gt; rows in SQL Profiler, and you will also notice that the first sample you could see it fill the screen line by line (I'm running this on a 1.8Ghz P4 Toshiba notebook with 1Gb of memory) and the optimized sample flashes by and disappears in a split second (could have added some timing to the sample, but for clarity I keeping it as short as possible.&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff size=2&gt;The bottom line is that you need to understand your application behavior and tuning will make a big difference. With more options to tune SMO, the responsibility to tune your application has shifted to you, as SMO cannot guess what your application is going to request. &lt;I&gt;"With great power comes great responsibility"&lt;/I&gt; :-)&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;Next post will be on some of the more advanced tuning options SMO has to offer. If you have a special request about what you like me post on in the SMO space (or SQL-DMO, SQLCMD, OSQL, SQL WMI Provider, SQL Computer Manager, or XP's for that matter), then let me know.&lt;BR&gt;&lt;BR&gt;Michiel Wories (a PM on the SQL Server Team)&lt;BR&gt;---&lt;BR&gt;See also: &lt;A title=http://staff.develop.com/bobb/weblog/PermaLink.aspx?guid=0c070aff-a30f-4669-b0ae-ef7a2cde81c6 href="http://staff.develop.com/bobb/weblog/PermaLink.aspx?guid=0c070aff-a30f-4669-b0ae-ef7a2cde81c6" target=_blank&gt;http://staff.develop.com/bobb/weblog/PermaLink.aspx?guid=0c070aff-a30f-4669-b0ae-ef7a2cde81c6&lt;/A&gt;&lt;BR&gt;---&lt;BR&gt;This posting is provided "AS IS" with no warranties, and confers no rights. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=410875" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mwories/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/mwories/archive/tags/SMO+Samples/default.aspx">SMO Samples</category></item></channel></rss>