<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-31397272</id><updated>2010-02-07T05:42:33.615-05:00</updated><title type='text'>Random Thunks</title><subtitle type='html'>Spurious non-linear technical thunks from the words formost authority in useless random thunking.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://random-thunks.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default'/><link rel='alternate' type='text/html' href='http://random-thunks.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default?start-index=26&amp;max-results=25'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>50</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-31397272.post-1924529222977135914</id><published>2009-11-18T15:03:00.001-05:00</published><updated>2009-11-18T15:38:36.276-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Workarounds'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR'/><title type='text'>Deploying signed assemblies in a single script</title><content type='html'>&lt;p&gt;I’ve been writing a set of routines to control my database backups recently and one part of this was a CLR User Defined Data Type I’d created that allows some rudimentary file handling (with the appropriate security). By it’s very nature this assembly required the &lt;font color="#0000ff" face="Consolas"&gt;EXTERNAL ACCESS&lt;/font&gt; privilege and this is where the head-scratching came about.&lt;/p&gt; &lt;p&gt;Liking clean install scripts with minimal payloads (single scripts are easier to check into Source Code and deploy across multiple environments) I needed some method of encapsulating the deploy and ensuring the appropriate asymmetric key, users etc. were created. However normally this would require either the key file or the assembly DLL to be copied along with the .Sql script – and this would break my 1 script rule! So next idea was to create the asymmetric key from the assembly directly within Sql server – but I couldn’t do that until I’d installed the assembly which would fail because it required the &lt;font color="#0000ff" face="Consolas"&gt;EXTERNAL ACCESS&lt;/font&gt; privilege; Thus leading to another game of Chicken and Egg.&lt;/p&gt; &lt;p&gt;The solution was remarkably obvious – use a temporary &lt;font color="#0000ff" face="Consolas"&gt;SAFE&lt;/font&gt; assembly to create the asymmetric key then dispose of it directly afterwards – after all the assembly is only required at this juncture to create the asymmetric key.&lt;/p&gt; &lt;p&gt;The first section of the script deals with previous execution cleanups etc:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:30f3a402-c6a8-42b6-9337-3e8a64d74ff5" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Use&lt;/span&gt; RandomThunks&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;------------/ Start stage 1 : Drop previous objects /--------------------------------------------------&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;assembly_types&lt;/span&gt; &lt;span style="color:#0000ff"&gt;As&lt;/span&gt; T &lt;span style="color:#808080"&gt;Inner&lt;/span&gt; &lt;span style="color:#808080"&gt;Join&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;schemas&lt;/span&gt; &lt;span style="color:#0000ff"&gt;As&lt;/span&gt; S &lt;span style="color:#0000ff"&gt;On&lt;/span&gt; T&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;schema_id&lt;/span&gt; &lt;span style="color:#808080"&gt;=&lt;/span&gt; S&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;schema_id&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; T&lt;span style="color:#808080"&gt;.&lt;/span&gt;name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;N&amp;#39;SqlFile&amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;And&lt;/span&gt; S&lt;span style="color:#808080"&gt;.&lt;/span&gt;Name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;N&amp;#39;Maintenance.Database.Archives&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Type&lt;/span&gt; [Maintenance.Database.Archives]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SqlFile&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;assemblies&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;N&amp;#39;RandomThunks.CLR.SqlServerFileUDT&amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;and&lt;/span&gt; is_user_defined &lt;span style="color:#808080"&gt;=&lt;/span&gt; 1&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [Skipjack.CLR.SqlServerFileUDT]&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;-- This next key should never exist when we run this as it&amp;#39;s only use to create the asymmetric key before we Grant the External Access right to it.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;assemblies&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;N&amp;#39;TEMPORARY. DO NOT USE!&amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;and&lt;/span&gt; is_user_defined &lt;span style="color:#808080"&gt;=&lt;/span&gt; 1&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [TEMPORARY. DO NOT USE!]&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;server_principals&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;SqlServerFileUDTUser&amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Login&lt;/span&gt; SqlServerFileUDTUser&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;asymmetric_keys&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;SqlServerFileUDTKey&amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Asymmetric&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Key&lt;/span&gt; SqlServerFileUDTKey&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;------------/ End stage 1 : Drop previous objects /----------------------------------------------------&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;blockquote&gt; &lt;p&gt;And the second part deploys the assembly with the requisite privilege:&lt;/p&gt;&lt;/blockquote&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4be27992-53d6-4b93-a1da-f181fc146459" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;------------/ Start stage 2 : Object Creation /--------------------------------------------------------&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Declare&lt;/span&gt; @Assembly &lt;span style="color:#0000ff"&gt;VarBinary&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;MAX&lt;/span&gt;&lt;span style="color:#808080"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Set&lt;/span&gt; @Assembly &lt;span style="color:#808080"&gt;=&lt;/span&gt; 0x4D5A9000030000000&lt;span style="color:#808080"&gt;...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Not&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;schemas&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; Name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;Maintenance.Database.Archives&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_ExecuteSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;Create Schema [Maintenance.Database.Archives]&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;-- Create a temporary assembly that we&amp;#39;ll use to build the Asymmetric Key from&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [TEMPORARY. DO NOT USE!] &lt;span style="color:#0000ff"&gt;Authorization&lt;/span&gt; dbo&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&lt;/span&gt; @Assembly&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;With&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Permission_Set&lt;/span&gt; &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Safe&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Asymmetric&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Key&lt;/span&gt; SqlServerFileUDTKey&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [TEMPORARY. DO NOT USE!]&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;-- Drop the temporary assembly - it&amp;#39;s use is over.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Drop&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [TEMPORARY. DO NOT USE!]&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Login&lt;/span&gt; SqlServerFileUDTUser&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Asymmetric&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Key&lt;/span&gt; SqlServerFileUDTKey&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;-- This needs to be run at the Server level - encapsulating it in a sp_ExecuteSql allows the script to be DB name agnostic.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_executeSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#ff0000"&gt;Use master;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#ff0000"&gt;Grant External Access Assembly&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#ff0000"&gt;To SqlServerFileUDTUser;&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;-- This is the real assembly&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Assembly&lt;/span&gt; [Skipjack.CLR.SqlServerFileUDT] &lt;span style="color:#0000ff"&gt;Authorization&lt;/span&gt; dbo&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&lt;/span&gt; @Assembly&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;With&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Permission_Set&lt;/span&gt; &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff"&gt;External_Access&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Type&lt;/span&gt; [Maintenance.Database.Archives]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SqlFile&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;External&lt;/span&gt; Name [RandomThunks.CLR.SqlServerFileUDT]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SqlFile&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;------------/ End stage 2 : Object Creation /----------------------------------------------------------&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-1924529222977135914?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/1924529222977135914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/11/deploying-signed-assemblies-in-single.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1924529222977135914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1924529222977135914'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/11/deploying-signed-assemblies-in-single.html' title='Deploying signed assemblies in a single script'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-8588351868973324625</id><published>2009-11-10T21:45:00.001-05:00</published><updated>2009-11-10T22:10:19.261-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='T-Sql'/><title type='text'>Sql Agent Session Storage</title><content type='html'>&lt;p&gt;I’ve been fiddling around with some jobs recently that required values to be kept from one job step to another. Not finding anything much exciting I went for plan Z – roll my own.&lt;/p&gt;  &lt;p&gt;They’re simple procedures but do work nicely.&lt;/p&gt;  &lt;p&gt;First I create a Schema that everything will be bundled under:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8839328a-95f7-4f9d-afae-90d08016f275" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Not&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; &lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;schemas&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; Name &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;Aracs.Utilities.Jobs&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_ExecuteSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;Create Schema [Aracs.Utilities.Jobs]&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now we’ll need a backing store:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0ca61a1f-35c3-4ea4-9ab4-fdbe5e812b18" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Table&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;JobId&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;UniqueIdentifier&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#808080"&gt;Not&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;ParameterName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;)&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#808080"&gt;Not&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;Value&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Sql_Variant&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next I create the &lt;strong&gt;SessionDestroyer&lt;/strong&gt; Procedure (since it can be called from the next one this keeps the dependencies happy and calm):&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5aa56f1c-7dbe-477c-a61c-3bb993b7eb5e" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Object_Id&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;[Aracs.Utilities.Jobs].SessionDestroyer&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt; &lt;span style="color:#808080"&gt;Is&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_ExecuteSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;Create Procedure [Aracs.Utilities.Jobs].SessionDestroyer As&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Go&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Alter&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Procedure&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionDestroyer&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;As&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Declare&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt; @JobHex&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;32&lt;span style="color:#808080"&gt;)&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@JobId&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;UniqueIdentifier&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Select&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;@JobHex &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Substring&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;Program_Name&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;dm_Exec_Sessions&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;Session_Id &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;@@Spid&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Delete&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Cast&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff"&gt;xml&lt;/span&gt;&lt;span style="color:#808080"&gt;).&lt;/span&gt;value&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;xs:hexBinary(sql:variable(&amp;quot;@JobHex&amp;quot;) )&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;VarBinary(MAX)&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Along comes the &lt;strong&gt;SessionSaverStore&lt;/strong&gt; next:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c660fb51-fc32-482a-8e4d-515ed0c67877" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Object_Id&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;[Aracs.Utilities.Jobs].SessionSaverStore&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt; &lt;span style="color:#808080"&gt;Is&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Create&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Table&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;JobId&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;UniqueIdentifier&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;ParameterName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;Value&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Sql_Variant&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Object_Id&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;[Aracs.Utilities.Jobs].SessionSaver&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt; &lt;span style="color:#808080"&gt;Is&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_ExecuteSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;Create Procedure [Aracs.Utilities.Jobs].SessionSaver As&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Go&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Alter&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Procedure&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaver&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;@ParameterName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@Value&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Sql_Variant&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@StartFresh&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Bit&lt;/span&gt; &lt;span style="color:#808080"&gt;=&lt;/span&gt; 0&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;As&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Declare&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt; @JobHex&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;32&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@JobId&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;UniqueIdentifier&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Select&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;@JobHex &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Substring&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;Program_Name&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;dm_Exec_Sessions&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;Session_Id &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;@@Spid&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Set&lt;/span&gt; @JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Cast&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff"&gt;xml&lt;/span&gt;&lt;span style="color:#808080"&gt;).&lt;/span&gt;value&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;xs:hexBinary(sql:variable(&amp;quot;@JobHex&amp;quot;) )&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;VarBinary(MAX)&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;);&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; MSDB&lt;span style="color:#808080"&gt;.&lt;/span&gt;dbo&lt;span style="color:#808080"&gt;.&lt;/span&gt;sysJobs &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; Job_Id &lt;span style="color:#808080"&gt;=&lt;/span&gt; @JobId &lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Begin&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; @StartFresh &lt;span style="color:#808080"&gt;=&lt;/span&gt; 1&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionDestroyer&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Select&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;1&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; @JobId&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;And&lt;/span&gt; ParameterName &lt;span style="color:#808080"&gt;=&lt;/span&gt; @ParameterName&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Update&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Set&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;Value &lt;span style="color:#808080"&gt;=&lt;/span&gt; @Value&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; @JobId&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;And&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;ParameterName &lt;span style="color:#808080"&gt;=&lt;/span&gt; @ParameterName&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Insert&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Into&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;JobId&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;ParameterName&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;Value&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Values&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;@JobId&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@ParameterName&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@Value&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;End&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally the &lt;strong&gt;SessionRetriever&lt;/strong&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:17870d90-f0db-47bb-949d-d0047f2361a0" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Object_Id&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;[Aracs.Utilities.Jobs].SessionRetriever&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;)&lt;/span&gt; &lt;span style="color:#808080"&gt;Is&lt;/span&gt; &lt;span style="color:#808080"&gt;Null&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; &lt;span style="color:#800000"&gt;sp_ExecuteSql&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;N&amp;#39;Create Procedure [Aracs.Utilities.Jobs].SessionRetriever As&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Go&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Alter&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Procedure&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionRetriever&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;@ParameterName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@Value&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Sql_Variant&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;Output&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;As&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Declare&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt; @JobHex&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;32&lt;span style="color:#808080"&gt;)&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@JobId&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;UniqueIdentifier&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@Valuei&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Sql_Variant&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;,&lt;/span&gt;@DataType&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;NVarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Select&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;@JobHex &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Substring&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff00ff"&gt;Program_Name&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;,&lt;/span&gt; 32&lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;span style="color:#008000"&gt;sys&lt;/span&gt;&lt;span style="color:#808080"&gt;.&lt;/span&gt;&lt;span style="color:#008000"&gt;dm_Exec_Sessions&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;Session_Id &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;@@Spid&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Set&lt;/span&gt; @JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Cast&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff"&gt;xml&lt;/span&gt;&lt;span style="color:#808080"&gt;).&lt;/span&gt;value&lt;span style="color:#808080"&gt;(&lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;xs:hexBinary(sql:variable(&amp;quot;@JobHex&amp;quot;) )&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;VarBinary(MAX)&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;);&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&amp;#160;&amp;#160;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;If&lt;/span&gt; &lt;span style="color:#808080"&gt;Exists&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff"&gt;Select&lt;/span&gt; 1 &lt;span style="color:#0000ff"&gt;From&lt;/span&gt; MSDB&lt;span style="color:#808080"&gt;.&lt;/span&gt;dbo&lt;span style="color:#808080"&gt;.&lt;/span&gt;sysJobs &lt;span style="color:#0000ff"&gt;Where&lt;/span&gt; Job_Id &lt;span style="color:#808080"&gt;=&lt;/span&gt; @JobId &lt;span style="color:#808080"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Begin&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Select&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;@Value &lt;span style="color:#808080"&gt;=&lt;/span&gt; Value&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;From&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaverStore&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Where&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;JobId &lt;span style="color:#808080"&gt;=&lt;/span&gt; @JobId&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#808080"&gt;And&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;ParameterName &lt;span style="color:#808080"&gt;=&lt;/span&gt; @ParameterName&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;End&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Use is pretty straightforward. As an Proof of concept I created a Sql Agent Job with two steps – Store’ and ‘Fetch’&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Store&lt;/strong&gt; contained the following:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:648b0a15-d947-4cd6-add5-21d125462e3c" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaver&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;Name&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39;Fred&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; 1&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt; [Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionSaver&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;Age&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; 37&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And &lt;strong&gt;Fetch&lt;/strong&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:995ba866-1b97-4e4a-9eb2-a2289332f7dd" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Declare&lt;/span&gt; @Name &lt;span style="color:#0000ff"&gt;Sql_Variant&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;Declare&lt;/span&gt; @Age &lt;span style="color:#0000ff"&gt;Sql_Variant&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionRetriever&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;Name&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; @Name &lt;span style="color:#0000ff"&gt;Output&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;Exec&lt;/span&gt;[Aracs.Utilities.Jobs]&lt;span style="color:#808080"&gt;.&lt;/span&gt;SessionRetriever&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;&amp;#39;Age&amp;#39;&lt;/span&gt;&lt;span style="color:#808080"&gt;,&lt;/span&gt; @Age &lt;span style="color:#0000ff"&gt;Output&lt;/span&gt;&lt;span style="color:#808080"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;Print&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Cast&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;@Name &lt;span style="color:#0000ff"&gt;As&lt;/span&gt; &lt;span style="color:#0000ff"&gt;VarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;128&lt;span style="color:#808080"&gt;))&lt;/span&gt; &lt;span style="color:#808080"&gt;+&lt;/span&gt; &lt;span style="color:#ff0000"&gt;&amp;#39; &amp;#39;&lt;/span&gt; &lt;span style="color:#808080"&gt;+&lt;/span&gt; &lt;span style="color:#ff00ff"&gt;Cast&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt; @Age &lt;span style="color:#0000ff"&gt;As&lt;/span&gt; &lt;span style="color:#0000ff"&gt;VarChar&lt;/span&gt;&lt;span style="color:#808080"&gt;(&lt;/span&gt;4&lt;span style="color:#808080"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Granted it’s missing some bells and whistles (like exception handling) and I’d wager I could stuff the Retriever in as a function. However as a first hit I was pretty chuffed with it!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-8588351868973324625?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/8588351868973324625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/11/sql-agent-session-storage.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8588351868973324625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8588351868973324625'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/11/sql-agent-session-storage.html' title='Sql Agent Session Storage'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-8586803760287837308</id><published>2009-10-19T09:55:00.001-04:00</published><updated>2009-10-20T07:07:11.550-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR'/><title type='text'>Bulk Copy within a Sql Server CLR Stored Procedure</title><content type='html'>&lt;p&gt;Whilst it’s not immediately obvious, one can perform a Bulk Copy operation as part of a Sql Server CLR Stored Procedure. There are however some gotcha’s.&lt;/p&gt;  &lt;p&gt;First off is that you need to stay away from Context Connections for the actual operation. Whilst you can technically use a Context Connection for the first part, I’d personally not recommend you do for reasons that will become apparent shortly.&lt;/p&gt;  &lt;p&gt;The code below is taken from one of my procedures using a homebrew class that provides me with information regarding a table – including the various elements of a fully qualified 4 part name (Server.Database.Schema.Table).&lt;/p&gt;  &lt;p&gt;The first part of the code handles the bulk import:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:aa2fdf4a-1d1a-4b1c-81b8-4c8d0eba65ba" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt; &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SqlConnection&lt;/span&gt; sourceCx = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;Data Source={0};Initial Catalog={1};Integrated Security=SSPI;&amp;quot;&lt;/span&gt;, sourceTable.ServerName, sourceTable.DatabaseName)))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;sourceCx.Open();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SqlCommand&lt;/span&gt; command = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;Select * From {0};&amp;quot;&lt;/span&gt;, sourceTable.FqTableName2Part), sourceCx))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SqlDataReader&lt;/span&gt; reader = command.ExecuteReader())&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SqlBulkCopy&lt;/span&gt; bulkCopy = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SqlBulkCopy&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;Data Source={0};Initial Catalog={1};Integrated Security=SSPI;&amp;quot;&lt;/span&gt;, destinationTable.ServerName, destinationTable.DatabaseName)))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.DestinationTableName = destinationTable.FqTableName2Part;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.SqlRowsCopied += &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SqlRowsCopiedEventHandler&lt;/span&gt;(bulkCopy_SqlRowsCopied);&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.DestinationTableName = destination;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.BatchSize = 10000;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.NotifyAfter = bulkCopy.BatchSize;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.WriteToServer(reader);&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;bulkCopy.Close();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As you can see I’m using two SSPI connections in place of the Context based Connection that’s normally provided. I decided to use SSPI to avoid needing to store user names and passwords. Your mileage and methodology may vary.&lt;/p&gt;  &lt;p&gt;The next section is the reason why I advise not using a Context Connection for the &lt;font face="Consolas"&gt;DataReader&lt;/font&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:07aa69de-3eac-486f-aa9a-95b797201c92" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; bulkCopy_SqlRowsCopied(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;SqlRowsCopiedEventArgs&lt;/span&gt; e)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; call = &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;RaisError(&amp;#39;{0} rows copied&amp;#39;, 0, 0) With NoWait&amp;quot;&lt;/span&gt;, e.RowsCopied);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#2b91af"&gt;SqlContext&lt;/span&gt;.Pipe.ExecuteAndSend(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SqlCommand&lt;/span&gt;(call));&amp;#160;&amp;#160;&lt;/li&gt; &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In order for this event to work correctly the Context Connection &lt;em&gt;must be free&lt;/em&gt; – which will not be the case if you use it for the &lt;font face="Consolas"&gt;DataReader&lt;/font&gt;. Running the &lt;font face="Consolas"&gt;RaisError&lt;/font&gt; via &lt;font face="Consolas"&gt;ExecuteAndSend&lt;/font&gt; ensures the results are not gobbled up by the any special pipe that &lt;font face="Consolas"&gt;SqlCommand.ExecuteNoQuery&lt;/font&gt; creates (see Vadim Tryshev’s excellent post on &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlnetfx/thread/416ce632-ea3b-417b-833b-6036e86af6e7#998acb24-17fc-4940-8bea-528fee301213" target="_blank"&gt;RAISERROR in CLR Routines&lt;/a&gt;). Finally I use a 0 for both the State and Severity to avoid any subsequent messages that &lt;font face="Consolas"&gt;RaisError&lt;/font&gt; would otherwise produce.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#ff8000" size="1"&gt;Sql Server 2008, SP1&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-8586803760287837308?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/8586803760287837308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/10/bulk-copy-within-sql-server-clr-stored.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8586803760287837308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8586803760287837308'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/10/bulk-copy-within-sql-server-clr-stored.html' title='Bulk Copy within a Sql Server CLR Stored Procedure'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-1084425015253507984</id><published>2009-09-28T13:58:00.001-04:00</published><updated>2009-09-28T14:35:46.505-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Odd'/><title type='text'>Wither ‘Go’</title><content type='html'>&lt;p&gt;Wow, it’s been another time and a bit since my last post. Still here, still banging my head against the proverbial wall…&lt;/p&gt; &lt;p&gt;Came across this Oddness today.&lt;/p&gt; &lt;p&gt;I had the following script segment:&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    If &lt;/span&gt;&lt;span style="color: gray"&gt;Exists ( &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;1 &lt;span style="color: blue"&gt;From &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;tables &lt;/span&gt;&lt;span style="color: blue"&gt;Where &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: red"&gt;'Security.Dictionary'&lt;/span&gt;&lt;span style="color: gray"&gt;) )&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;Drop Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;span style="color: gray"&gt;;&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Create Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;br /&gt;        &lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;Id                        &lt;span style="color: blue"&gt;Int Identity&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;1&lt;span style="color: gray"&gt;, &lt;/span&gt;1&lt;span style="color: gray"&gt;) Not Null&lt;br /&gt;                ,&lt;/span&gt;HashValue                 &lt;span style="color: blue"&gt;Int &lt;/span&gt;&lt;span style="color: gray"&gt;Not Null&lt;br /&gt;                ,&lt;/span&gt;ItemType                  &lt;span style="color: blue"&gt;TinyInt &lt;/span&gt;&lt;span style="color: gray"&gt;Null&lt;br /&gt;                ,&lt;/span&gt;TextData                  &lt;span style="color: blue"&gt;NVarChar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: magenta"&gt;MAX&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;        );&lt;/span&gt;&lt;br /&gt;&lt;span style="color: gray"&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;br /&gt;    Alter Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary &lt;span style="color: blue"&gt;With NoCheck&lt;br /&gt;        Add Constraint &lt;/span&gt;PK_Dictionary &lt;span style="color: blue"&gt;Primary Key NonClustered &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;             &lt;/span&gt;HashValue&lt;br /&gt;        &lt;span style="color: gray"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;With&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;&lt;span style="color: blue"&gt;FillFactor &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;50&lt;br /&gt;                &lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Online &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Pad_Index &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Row_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Page_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;Off&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;    ;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;I needed to Add &lt;strong&gt;ItemType&lt;/strong&gt; to the clustered key, so I dutifully made it a &lt;strong&gt;Not Null&lt;/strong&gt; and tried again. &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    If &lt;/span&gt;&lt;span style="color: gray"&gt;Exists ( &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;1 &lt;span style="color: blue"&gt;From &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;tables &lt;/span&gt;&lt;span style="color: blue"&gt;Where &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: red"&gt;'Security.Dictionary'&lt;/span&gt;&lt;span style="color: gray"&gt;) )&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;Drop Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;span style="color: gray"&gt;;&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Create Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;br /&gt;        &lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;Id                        &lt;span style="color: blue"&gt;Int Identity&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;1&lt;span style="color: gray"&gt;, &lt;/span&gt;1&lt;span style="color: gray"&gt;) Not Null&lt;br /&gt;                ,&lt;/span&gt;HashValue                 &lt;span style="color: blue"&gt;Int &lt;/span&gt;&lt;span style="color: gray"&gt;Not Null&lt;br /&gt;                ,&lt;/span&gt;ItemType                  &lt;span style="color: blue"&gt;TinyInt &lt;/span&gt;&lt;span style="color: gray"&gt;Not Null&lt;br /&gt;                ,&lt;/span&gt;TextData                  &lt;span style="color: blue"&gt;NVarChar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: magenta"&gt;MAX&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;        );&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;br /&gt;    Alter Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary &lt;span style="color: blue"&gt;With NoCheck&lt;br /&gt;        Add Constraint &lt;/span&gt;PK_Dictionary &lt;span style="color: blue"&gt;Primary Key NonClustered &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;             &lt;/span&gt;HashValue&lt;br /&gt;            &lt;span style="color: gray"&gt;,&lt;/span&gt;ItemType&lt;br /&gt;        &lt;span style="color: gray"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;With&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;&lt;span style="color: blue"&gt;FillFactor &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;50&lt;br /&gt;                &lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Online &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Pad_Index &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Row_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Page_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;Off&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;    ;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;Imagine my puzzlement when I received the following error:&lt;br /&gt;&lt;font color="#ff0000" face="Consolas"&gt;&lt;br /&gt;Msg 8111, Level 16, State 1, Line 12&lt;br /&gt;Cannot define PRIMARY KEY constraint on nullable column in table 'Dictionary'.&lt;br /&gt;Msg 1750, Level 16, State 0, Line 12&lt;br /&gt;Could not create constraint. See previous errors.&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;This threw me for a loop since &lt;strong&gt;ItemType&lt;/strong&gt; was quite clearly &lt;strong&gt;Not Null&lt;/strong&gt; (Line 9). So I ran each segment in turn using &lt;strong&gt;Select&lt;/strong&gt; and &lt;strong&gt;F5&lt;/strong&gt; and was even more non-plussed when each segment ran fine. I then ran the script again and once more, it ran without failure. With my trusty imaginary ‘WTF?’ Red Fez hat firmly planted on my noggin, I attempted to recreate the situation and low and behold I found that adding a &lt;strong&gt;Go&lt;/strong&gt; batch separator thus separating the &lt;strong&gt;Create Table&lt;/strong&gt; And the &lt;strong&gt;Alter Table&lt;/strong&gt; made all the difference for the first run through: &lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    If &lt;/span&gt;&lt;span style="color: gray"&gt;Exists ( &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;1 &lt;span style="color: blue"&gt;From &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;tables &lt;/span&gt;&lt;span style="color: blue"&gt;Where &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Id&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: red"&gt;'Security.Dictionary'&lt;/span&gt;&lt;span style="color: gray"&gt;) )&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;Drop Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;span style="color: gray"&gt;;&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Create Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary&lt;br /&gt;        &lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;Id                        &lt;span style="color: blue"&gt;Int Identity&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;1&lt;span style="color: gray"&gt;, &lt;/span&gt;1&lt;span style="color: gray"&gt;) Not Null&lt;br /&gt;                ,&lt;/span&gt;HashValue                 &lt;span style="color: blue"&gt;Int &lt;/span&gt;&lt;span style="color: gray"&gt;Not Null&lt;br /&gt;                ,&lt;/span&gt;ItemType                  &lt;span style="color: blue"&gt;TinyInt &lt;/span&gt;&lt;span style="color: gray"&gt;Not Null&lt;br /&gt;                ,&lt;/span&gt;TextData                  &lt;span style="color: blue"&gt;NVarChar&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: magenta"&gt;MAX&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;        );&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;Go&lt;br /&gt;&lt;br /&gt;    Alter Table &lt;/span&gt;[Security]&lt;span style="color: gray"&gt;.&lt;/span&gt;Dictionary &lt;span style="color: blue"&gt;With NoCheck&lt;br /&gt;        Add Constraint &lt;/span&gt;PK_Dictionary &lt;span style="color: blue"&gt;Primary Key NonClustered &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;             &lt;/span&gt;HashValue&lt;br /&gt;            &lt;span style="color: gray"&gt;,&lt;/span&gt;ItemType&lt;br /&gt;        &lt;span style="color: gray"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;With&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;                 &lt;/span&gt;&lt;span style="color: blue"&gt;FillFactor &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;50&lt;br /&gt;                &lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Online &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Pad_Index &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Row_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;On&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: blue"&gt;Allow_Page_Locks &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: blue"&gt;Off&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;    ;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;If I were to guess what just happend here I'd say that I think the &lt;Strong&gt;Alter Table&lt;/Strong&gt; sans the &lt;Strong&gt;Go&lt;/Strong&gt; seperator was parsed based off the previous table specification, however embedding the &lt;Strong&gt;Go&lt;/Strong&gt; seperator forced the parser to re-evaluate the new layout. Or something...&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;font color="#ff8000" size="1"&gt;Sql Server 2008, SP1&lt;/font&gt;&lt;/em&gt; &lt;/div&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-1084425015253507984?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/1084425015253507984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/09/wither-go.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1084425015253507984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1084425015253507984'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/09/wither-go.html' title='Wither ‘Go’'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-7820415115640909681</id><published>2009-04-30T10:03:00.001-04:00</published><updated>2009-04-30T10:03:43.002-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Off topic'/><category scheme='http://www.blogger.com/atom/ns#' term='Current Events'/><category scheme='http://www.blogger.com/atom/ns#' term='Humor'/><title type='text'>We interrupt your schedule to bring you this late breaking news</title><content type='html'>&lt;p&gt;Off topic, however worthy of keeping for posterity. From the Department of Homeland Security comes &lt;a href="http://www.dhs.gov/ynews/releases/pr_1241056994692.shtm" target="_blank"&gt;this press release&lt;/a&gt; from the Office of the Press Secretary, and a statement on just how serious the US Government is on eradicating the 2009 H1N1 ‘Swine Flu’ virus.&lt;/p&gt;  &lt;p&gt;And just incase they redact their statement, here’s the most chilling section:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://attachments.random-thunks.com/Weinterruptyourscheduletobringyouthislat_8D79/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://attachments.random-thunks.com/Weinterruptyourscheduletobringyouthislat_8D79/image_thumb.png" width="543" height="293" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;One hopes this was a simple typo!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-7820415115640909681?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/7820415115640909681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/04/we-interrupt-your-schedule-to-bring-you.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/7820415115640909681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/7820415115640909681'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/04/we-interrupt-your-schedule-to-bring-you.html' title='We interrupt your schedule to bring you this late breaking news'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-6229416994811512217</id><published>2009-04-14T15:44:00.001-04:00</published><updated>2009-04-14T15:45:55.466-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><title type='text'>There can be only 1</title><content type='html'>&lt;p&gt;Our resident architect came over today and posed me this little puzzler – he wanted a query that would return if 1 row or nothing based of a certain criteria. In other words if two rows met the criteria he wanted nothing pulled back.&lt;/p&gt;  &lt;p&gt;A strange request I’ll grant ye, and one that took me some time to bang my head against, however the answer was pretty neat:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Create Schema &lt;/span&gt;Test&lt;span style="color: gray"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;Go&lt;br /&gt;&lt;br /&gt;Create Table &lt;/span&gt;Test&lt;span style="color: gray"&gt;.&lt;/span&gt;Only1RowTest&lt;br /&gt;&lt;span style="color: gray"&gt;(&lt;br /&gt;         &lt;/span&gt;Key1    &lt;span style="color: blue"&gt;Int&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;Key2    &lt;span style="color: blue"&gt;Int&lt;br /&gt;&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;Go&lt;br /&gt;&lt;br /&gt;Insert into &lt;/span&gt;Test&lt;span style="color: gray"&gt;.&lt;/span&gt;Only1RowTest &lt;span style="color: blue"&gt;Values &lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;1&lt;span style="color: gray"&gt;,&lt;/span&gt;1&lt;span style="color: gray"&gt;),(&lt;/span&gt;2&lt;span style="color: gray"&gt;,&lt;/span&gt;2&lt;span style="color: gray"&gt;),(&lt;/span&gt;3&lt;span style="color: gray"&gt;,&lt;/span&gt;3&lt;span style="color: gray"&gt;),(&lt;/span&gt;1&lt;span style="color: gray"&gt;,&lt;/span&gt;2&lt;span style="color: gray"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: green"&gt;-- Demonstrate pulling back no rows because 2 rows meet the criteria&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;With &lt;/span&gt;Cte &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: gray"&gt;( &lt;/span&gt;&lt;span style="color: blue"&gt;Select Top&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;2&lt;span style="color: gray"&gt;) * &lt;/span&gt;&lt;span style="color: blue"&gt;From &lt;/span&gt;Test&lt;span style="color: gray"&gt;.&lt;/span&gt;Only1RowTest &lt;span style="color: blue"&gt;where &lt;/span&gt;Key1 &lt;span style="color: gray"&gt;= &lt;/span&gt;1  &lt;span style="color: gray"&gt;)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;Cte&lt;span style="color: gray"&gt;.* &lt;/span&gt;&lt;span style="color: blue"&gt;from &lt;/span&gt;Cte &lt;span style="color: gray"&gt;Inner Join  ( &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;&lt;span style="color: magenta"&gt;Count&lt;/span&gt;&lt;span style="color: gray"&gt;(*) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;c &lt;span style="color: blue"&gt;From &lt;/span&gt;Cte&lt;span style="color: gray"&gt;) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;CteC &lt;span style="color: blue"&gt;On &lt;/span&gt;CteC&lt;span style="color: gray"&gt;.&lt;/span&gt;c &lt;span style="color: gray"&gt;= &lt;/span&gt;1&lt;span style="color: gray"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: green"&gt;-- Expand the criteria to further limit the row count and we get 1&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;With &lt;/span&gt;Cte &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: gray"&gt;( &lt;/span&gt;&lt;span style="color: blue"&gt;Select Top&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;2&lt;span style="color: gray"&gt;) * &lt;/span&gt;&lt;span style="color: blue"&gt;From &lt;/span&gt;Test&lt;span style="color: gray"&gt;.&lt;/span&gt;Only1RowTest &lt;span style="color: blue"&gt;where &lt;/span&gt;Key1 &lt;span style="color: gray"&gt;= &lt;/span&gt;1 &lt;span style="color: gray"&gt;And &lt;/span&gt;Key2 &lt;span style="color: gray"&gt;= &lt;/span&gt;1 &lt;span style="color: gray"&gt;)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;Cte&lt;span style="color: gray"&gt;.* &lt;/span&gt;&lt;span style="color: blue"&gt;from &lt;/span&gt;Cte &lt;span style="color: gray"&gt;Inner Join  ( &lt;/span&gt;&lt;span style="color: blue"&gt;Select &lt;/span&gt;&lt;span style="color: magenta"&gt;Count&lt;/span&gt;&lt;span style="color: gray"&gt;(*) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;c &lt;span style="color: blue"&gt;From &lt;/span&gt;Cte&lt;span style="color: gray"&gt;) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;CteC &lt;span style="color: blue"&gt;On &lt;/span&gt;CteC&lt;span style="color: gray"&gt;.&lt;/span&gt;c &lt;span style="color: gray"&gt;= &lt;/span&gt;1&lt;span style="color: gray"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;To break it down further, we create a common table expression and start off on the basis that returning 2 rows is just as bad as returning 2 million, so we limit the rows pulled back with a Top(2), we then bring back the results of the CTE as long as the # of rows returned =1 (no-one ever said an Inner Join had to join two columns together).&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;em&gt;&lt;font color="#ff8000" size="1"&gt;Sql Server 2008 Build 10.0.1798.0 (RTM-CU4)&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-6229416994811512217?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/6229416994811512217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/04/there-can-be-only-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/6229416994811512217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/6229416994811512217'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/04/there-can-be-only-1.html' title='There can be only 1'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-3270075278385652283</id><published>2009-03-26T16:38:00.013-04:00</published><updated>2009-03-26T17:05:27.047-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Resource Governor'/><title type='text'>Fritzin’ with the Guv’nor</title><content type='html'>&lt;p&gt;It’s a feature I for one have been screaming desperate for – the &lt;strong&gt;Sql Server 2008 Resource Governor&lt;/strong&gt; – the means to finally provide a T-SQL based process to throttle how much CPU and Memory certain activities can utilize.&lt;/p&gt;  &lt;p&gt;For me I need to it because I hate bringing the server down every time I need to run a fragmentation scan; with a 1.5TB DB on an undersized server, I need most of the resources dedicated to keeping the application happy. However I don’t want anything I do to kill the performance – and likewise I don’t want some schmuck running a badly written adhoc query in Management Studio preventing me from doing my job.&lt;/p&gt;  &lt;p&gt;And this is where the Resource Governor comes in to play by offering &lt;strong&gt;Resource Pools&lt;/strong&gt; and &lt;strong&gt;Work Groups&lt;/strong&gt;.  Each Pool can be though of almost as an individual Sql Server instance operating on shared data.And to a certain extent this is true, however the pools do share some meta-data which I’ll explain later.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image.png"&gt;&lt;img style="border: 0px none ; display: inline; margin-left: 0px; margin-right: 0px;" title="image" alt="image" src="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_thumb.png" width="234" align="left" border="0" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Out of the box there are 2 Pools and 2 Groups pre-defined – One called Internal which is static and immutable and where Sql Server processes its internal processes, the other called Default which contains a undeletable but otherwise configurable group, also called Default.&lt;/p&gt;  &lt;p&gt;In this configuration and user processing is performed in the Default Pool and all internal processing is carried on in the Internal pool – even to the detriment of any other pool out there. This allows Sql Server to continue processing without other pools pressurizing it and as a result, no user processes are allowed in the Internal pool.&lt;/p&gt;  &lt;p&gt;Pools are the first level of control and are used to define the minimum and maximum CPU and memory workloads running inside them are ever allowed to use. Work Groups take it to the next level and allow not only a finer level of control but also the ability to move them between pools. Groups, for example can be defined to specify how much of a % they take out of the pool, the priority level and also the MAXDOP setting. Finally, users are associated with pools via use of a &lt;strong&gt;Classification Function&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;However, it is important to understand that the Resource Governor really only limits resources when there is a pinch point in total resource availability. Running identical queries on an otherwise silent server, one in a High priority pool and the other in a low one will have no obvious effect. However once the server is being pushed the resource governor provides a nice guarantee of resource availability to those sessions that require it and a good throttle to those that don’t.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_3.png"&gt;&lt;img style="border: 0px none ; display: inline; margin-left: 0px; margin-right: 0px;" title="image" alt="image" src="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_thumb_3.png" width="427" align="right" border="0" height="239" /&gt;&lt;/a&gt; In the examples that follows I use two new pools and one associated work group in each pool. One pool will be used to process high priority tasks and the other low priority. Two users will be created, one will be assigned to the High Work Group, the other the Low Work Group.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;(NB: for brevities sake the users I’m creating here do not have any passwords; it goes without saying that this is exceptionally bad form and should not be practiced on any server that you value data, schema or any other objects on!)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="code"&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Create Resource Pool &lt;/span&gt;Low &lt;span style="color:blue;"&gt;With &lt;/span&gt;&lt;span style="color:gray;"&gt;( &lt;/span&gt;Min_CPU_Percent&lt;wbr&gt; &lt;span style="color:gray;"&gt;= &lt;/span&gt;0&lt;span style="color:gray;"&gt;, &lt;/span&gt;Max_CPU_Percent&lt;wbr&gt; &lt;span style="color:gray;"&gt;= &lt;/span&gt;30 &lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;) ;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create Resource Pool &lt;/span&gt;High &lt;span style="color:blue;"&gt;With &lt;/span&gt;&lt;span style="color:gray;"&gt;( &lt;/span&gt;Min_CPU_Percent&lt;wbr&gt; &lt;span style="color:gray;"&gt;= &lt;/span&gt;60&lt;span style="color:gray;"&gt;, &lt;/span&gt;Max_CPU_Percent&lt;wbr&gt; &lt;span style="color:gray;"&gt;= &lt;/span&gt;100 &lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;) ;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create Workload Group &lt;/span&gt;Low &lt;span style="color:blue;"&gt;With &lt;/span&gt;&lt;span style="color:gray;"&gt;( &lt;/span&gt;Importance &lt;span style="color:gray;"&gt;= &lt;/span&gt;Low &lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;Using &lt;/span&gt;Low&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create Workload Group &lt;/span&gt;High &lt;span style="color:blue;"&gt;With &lt;/span&gt;&lt;span style="color:gray;"&gt;( &lt;/span&gt;Importance &lt;span style="color:gray;"&gt;= &lt;/span&gt;High&lt;span style="color:gray;"&gt;, &lt;/span&gt;Request_Max_Mem&lt;wbr&gt;ory_Grant_Perce&lt;wbr&gt;nt &lt;span style="color:gray;"&gt;= &lt;/span&gt;100 &lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;Using &lt;/span&gt;High&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Alter Resource Governor Reconfigure&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Use &lt;/span&gt;AdventureWorks2&lt;wbr&gt;008&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create Login &lt;/span&gt;LowUser &lt;span style="color:blue;"&gt;With Password&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:red;"&gt;N''&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Default_Databas&lt;wbr&gt;e&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;AdventureWorks2&lt;wbr&gt;008&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Check_Expiratio&lt;wbr&gt;n&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:blue;"&gt;Off&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Check_Policy&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:blue;"&gt;Off&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create &lt;/span&gt;&lt;span style="color:magenta;"&gt;User &lt;/span&gt;LowUser &lt;span style="color:blue;"&gt;For Login &lt;/span&gt;LowUser&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Exec &lt;/span&gt;&lt;span style="color:maroon;"&gt;sp_AddRoleMembe&lt;wbr&gt;r &lt;/span&gt;&lt;span style="color:red;"&gt;N'db_owner'&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:red;"&gt;N'LowUser'&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create Login &lt;/span&gt;HighUser &lt;span style="color:blue;"&gt;With Password&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:red;"&gt;N''&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Default_Databas&lt;wbr&gt;e&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;AdventureWorks2&lt;wbr&gt;008&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Check_Expiratio&lt;wbr&gt;n&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:blue;"&gt;Off&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:blue;"&gt;Check_Policy&lt;/span&gt;&lt;span style="color:gray;"&gt;=&lt;/span&gt;&lt;span style="color:blue;"&gt;Off&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Create &lt;/span&gt;&lt;span style="color:magenta;"&gt;User &lt;/span&gt;HighUser &lt;span style="color:blue;"&gt;For Login &lt;/span&gt;HighUser&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Exec &lt;/span&gt;&lt;span style="color:maroon;"&gt;sp_AddRoleMembe&lt;wbr&gt;r &lt;/span&gt;&lt;span style="color:red;"&gt;N'db_owner'&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;span style="font-family:Consolas;"&gt;N'HighUser'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br/&gt;As can be seen, the Low pool is only given 30% of CPU to play with – however this is not a true maximum but for these examples it’s good enough. I’ll explain these figures and how they interact later. Notice also the statement reconfiguring the governor; no changes are ever made until this Reconfiguration&lt;wbr&gt; has taken place.&lt;br /&gt;&lt;br/&gt;Next we need to be ability associate users with workgroups – something that’s facilitated with a Scalar-based classification function. This function can make its decision based on numerous factors, including (but not limited to) session user name, host name and application name. For now we’ll keep it very simple and base it off the user name.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-family:Consolas;"&gt;Use master&lt;/span&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;&lt;span style="font-family:Consolas;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Go&lt;br /&gt;&lt;br /&gt;Create Function    &lt;/span&gt;dbo&lt;span style="color:gray;"&gt;.&lt;/span&gt;ResourceGoverno&lt;wbr&gt;rWorkgroupClass&lt;wbr&gt;ifier&lt;/span&gt;&lt;span style="color:gray;"&gt;&lt;span style="font-family:Consolas;"&gt;()&lt;br /&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Returns    sysname&lt;br /&gt;   With SchemaBinding&lt;br /&gt;As&lt;br /&gt;   Begin&lt;br /&gt;&lt;br /&gt;       Declare         &lt;/span&gt;@WorkgroupName                &lt;span style="color:blue;"&gt;SysName            &lt;/span&gt;&lt;span style="color:gray;"&gt;= &lt;/span&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;span style="font-family:Consolas;"&gt;'default'&lt;br /&gt;       &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;      &lt;br /&gt;       &lt;/span&gt;&lt;span style="color:blue;"&gt;If &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUser_Name&lt;/span&gt;&lt;span style="color:gray;"&gt;() = &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:red;"&gt;'LowUser'&lt;br /&gt;           &lt;/span&gt;&lt;span style="color:blue;"&gt;Set &lt;/span&gt;@WorkgroupName &lt;span style="color:gray;"&gt;= &lt;/span&gt;&lt;span style="color:red;"&gt;'Low'&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;      &lt;br /&gt;       &lt;/span&gt;&lt;span style="color:blue;"&gt;If &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUser_Name&lt;/span&gt;&lt;span style="color:gray;"&gt;() = &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:red;"&gt;'HighUser'&lt;br /&gt;           &lt;/span&gt;&lt;span style="color:blue;"&gt;Set &lt;/span&gt;@WorkgroupName &lt;span style="color:gray;"&gt;= &lt;/span&gt;&lt;span style="color:red;"&gt;'High'&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;/span&gt;&lt;span style="color:blue;"&gt;Return &lt;/span&gt;@WorkGroupName&lt;/span&gt;&lt;span style="color:gray;"&gt;&lt;span style="font-family:Consolas;"&gt;;&lt;br /&gt;      &lt;br /&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;End&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;Alter Resource Governor With &lt;/span&gt;&lt;span style="color:gray;"&gt;( &lt;/span&gt;Classifier_Function &lt;span style="color:gray;"&gt;= &lt;/span&gt;dbo&lt;span style="color:gray;"&gt;.&lt;/span&gt;ResourceGoverno&lt;wbr&gt;rWorkgroupClass&lt;wbr&gt;ifier&lt;span style="color:gray;"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;This really simple classifier function simply assumes user will be allocated to the “default” work group unless either LowUser or HighUser logs in, at which point they’ll be allocated to the relevant Work Groups. This function will now be executed for every subsequent user login – so as a result you’ll always want to keep this function as short and sweet as possible (a reconfiguration&lt;wbr&gt; is &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; required for this to take a effect).&lt;br /&gt;&lt;br/&gt;So, now we’re ready to demonstrate the Resource Governor in action. Now, remember earlier I mentioned the governor only kicks in when there’s a pressure point? This being the case we need a method of creating an artificial resource hog – something that will thrash the DB nicely. The &lt;span style="color:#0000ff;"&gt;AdventureWorks2&lt;wbr&gt;008.Sales.Sales&lt;wbr&gt;OrderDetail&lt;/span&gt; table is a nice enough size for us to run some hairy and not so hairy queries against. &lt;em&gt;Caveat emptor – the queries themselves are totally nonsensical – they are written to provide example load usage only.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;Run the following in a session as a ‘normal’ user (sa, your Windows account or anything else):&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;pre class="code"&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Select &lt;/span&gt;&lt;span style="color:magenta;"&gt;COUNT&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;(*)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;From &lt;/span&gt;Sales&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;l &lt;span style="color:blue;"&gt;As &lt;/span&gt;Sod1&lt;br /&gt;&lt;span style="color:gray;"&gt;Inner Join &lt;/span&gt;Sales&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;l &lt;span style="color:blue;"&gt;As &lt;/span&gt;Sod2 &lt;span style="color:blue;"&gt;On &lt;/span&gt;Sod1&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;lID &lt;span style="color:gray;"&gt;!= &lt;/span&gt;Sod2&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;lID&lt;span style="color:#808080;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br/&gt;Even on a relatively beefy PC this should begin to the thrash the living bejezus out of Sql Server and take the CPU close to 100%. Now connect a session as &lt;span style="color:#ff0000;"&gt;LowUser&lt;/span&gt; and run:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;pre class="code"&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Set Statistics Time On&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Select &lt;/span&gt;&lt;span style="color:magenta;"&gt;COUNT&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;(*)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;From &lt;/span&gt;Sales&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;l &lt;span style="color:blue;"&gt;As &lt;/span&gt;Sod1&lt;br /&gt;&lt;span style="color:gray;"&gt;Inner Join &lt;/span&gt;Sales&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;l &lt;span style="color:blue;"&gt;As &lt;/span&gt;Sod2 &lt;span style="color:blue;"&gt;On &lt;/span&gt;Sod1&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;lID &lt;span style="color:gray;"&gt;!= &lt;/span&gt;Sod2&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderDetai&lt;wbr&gt;lID&lt;span style="color:#808080;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:gray;"&gt;And &lt;/span&gt;Sod1&lt;span style="color:gray;"&gt;.&lt;/span&gt;SalesOrderID &lt;span style="color:gray;"&gt;&amp;lt; &lt;/span&gt;43800&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;Finally, connect a third session as &lt;span style="color:#ff0000;"&gt;HighUser&lt;/span&gt; and run the same query. If all goes well, this last query should finish relatively quickly (for me it takes between 10 and 15 seconds), however the second query (running as &lt;span style="color:#ff0000;"&gt;LowUser&lt;/span&gt;) should take considerably longer (for me it was a shade over 2 minutes). If all is well the first control query should still be running (and still consuming the very soul out of your CPUs). If I were you I’d kill this initial query off now if it’s still going. It’ll do nothing for the performance of your PC!&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;a href="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_4.png"&gt;&lt;img style="border: 0px none ; display: inline; margin-left: 0px; margin-right: 0px;" title="image" alt="image" src="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_thumb_4.png" width="304" align="left" border="0" height="194" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;To see the true affect of the Governor, one simply has to compare the results produced by the time statistics. Whilst the actual CPU used by both queries is broadly the same, the elapsed time for low user is almost exponentially higher. This is directly the effect of running under the pool where the maximum CPU is capped at 30%. The figures here also show running the same queries under no stress to show that without putting the server under load, the governor makes very little difference.&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;Finally for this post (and don’t worry – there  will be a follow-up posting detailing some of the more intricate aspects of the Resource Governor) we’ll demonstrate another nice feature – moving Work Groups to different pools.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_5.png"&gt;&lt;img style="border: 0px none ; display: inline; margin-left: 0px; margin-right: 0px;" title="image" alt="image" src="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_thumb_5.png" width="400" align="right" border="0" height="205" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Moving a work group can be performed a any time, however the effect will only be felt with a Reconfiguration. Executing the following will result in an error:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;pre class="code"&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Alter Workload Group &lt;/span&gt;Low &lt;span style="color:blue;"&gt;Using &lt;/span&gt;High&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:gray;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;Alter Resource Governor Reconfigure&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;span style="font-family:Consolas;color:#ff0000;"&gt;Msg 10904, Level 16, State 2, Line 2&lt;br /&gt;    &lt;br /&gt;Resource governor configuration failed. There are active sessions in workload groups being dropped or moved to different resource pools. Disconnect all active sessions in the affected workload groups and try again.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;What is needed here is to disconnect any sessions currently utilizing the Low Work Group. We can utilize the following query to find out which sessions are affected and kill them off by hand (&lt;em&gt;&lt;strong&gt;and don’t forget to run the reconfiguration!&lt;/strong&gt;&lt;/em&gt;)&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;pre class="code"&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Select    &lt;/span&gt;Session_Id&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Consolas;"&gt;&lt;span style="color:blue;"&gt;Status&lt;br /&gt; From    &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;dm_exec_session&lt;wbr&gt;s &lt;/span&gt;&lt;span style="color:blue;"&gt;As &lt;/span&gt;S&lt;br /&gt;       &lt;span style="color:gray;"&gt;Inner Join &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;dm_resource_gov&lt;wbr&gt;ernor_workload_&lt;wbr&gt;groups &lt;/span&gt;&lt;span style="color:blue;"&gt;As &lt;/span&gt;G&lt;br /&gt;           &lt;span style="color:blue;"&gt;On &lt;/span&gt;S&lt;span style="color:gray;"&gt;.&lt;/span&gt;group_id &lt;span style="color:gray;"&gt;= &lt;/span&gt;G&lt;span style="color:gray;"&gt;.&lt;/span&gt;group_id&lt;br /&gt; &lt;span style="color:blue;"&gt;Where     &lt;/span&gt;G&lt;span style="color:gray;"&gt;.&lt;/span&gt;name &lt;span style="color:gray;"&gt;= &lt;/span&gt;&lt;span style="color:red;"&gt;'Low'&lt;span style="color:#808080;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now repeat the experiment by starting the Stress query first followed by the Low and finally the High.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_6.png"&gt;&lt;img style="border: 0px none ; display: inline;" title="image" alt="image" src="http://attachments.random-thunks.com/FritzinwiththeGvnor_BE51/image_thumb_6.png" width="550" border="0" height="314" /&gt;&lt;/a&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As you can see the elapsed time is significantly less when the Work Group is moved into the High Resource Pool. The reason for the discrepancy between the two is down to the configuration of the two groups; the High Group is set at a High Priority and allowed to utilize all of the RAM the pool has been allocated, whereas the Low Work Group is limited to being able to grab a maximum of 25% of memory from the pool (the default) and a relative importance setting of Low.&lt;br /&gt;&lt;br /&gt;That’s all for now – keep tuned for part two where we delve deeper into the mind of the guv’nor.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;font color="#ff8000" size="1"&gt;&lt;em&gt;Sql Server 2008 Build 10.0.1600.22 (RTM)&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-3270075278385652283?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/3270075278385652283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/03/fritzin-with-guvnor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3270075278385652283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3270075278385652283'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/03/fritzin-with-guvnor.html' title='Fritzin’ with the Guv’nor'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-7630803518479969267</id><published>2009-03-05T09:43:00.002-05:00</published><updated>2009-03-26T17:04:56.027-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Managment Studio'/><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><title type='text'>Sql Server 2008 Management Studio 'pings’</title><content type='html'>&lt;p&gt;Not had a chance to do a full investigation on this, however I did have a situation the other day where, despite me killing off all query connections and all connected Object Explorer windows, I still found that the 2008 Management Studio would ping one of my servers every three minutes or so. This only transpired because it was using an old cached Sql Server DB Principal password (I’d just changed it) and &lt;a href="http://www.quest.com/change-director-for-sql-server/"&gt;ChangeDirector&lt;/a&gt; was constantly wibbling about it.&lt;/p&gt;  &lt;p&gt;Killing off MS altogether stopped the issue dead in its tracks. If I get a chance to I might go back to finding out what the real story was, but a little puzzler it was at the time.&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000" size="1"&gt;&lt;em&gt;Sql Server 2008 Build 10.0.1600.22 (RTM)&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-7630803518479969267?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/7630803518479969267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/03/sql-server-2008-management-studio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/7630803518479969267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/7630803518479969267'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/03/sql-server-2008-management-studio.html' title='Sql Server 2008 Management Studio &amp;#39;pings’'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-6397906117989910917</id><published>2009-02-23T08:23:00.001-05:00</published><updated>2009-02-27T17:36:07.922-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Enhancements'/><category scheme='http://www.blogger.com/atom/ns#' term='ChangeDirector'/><category scheme='http://www.blogger.com/atom/ns#' term='Cluster'/><category scheme='http://www.blogger.com/atom/ns#' term='Quest'/><title type='text'>Clustering Quest ChangeDirector</title><content type='html'>&lt;p&gt;Whilst &lt;a href="http://www.quest.com/" target="_blank"&gt;Quest&lt;/a&gt; declare that &lt;a href="http://www.quest.com/change-director-for-sql-server/" target="_blank"&gt;ChangeDirector&lt;/a&gt; 2.1 supports Clustering I’m not convinced it goes the whole hog. However your intrepid Random-Thunker has gone through the small number of extra steps required to make it so.&lt;/p&gt;  &lt;p&gt;First off if you’ve not already done so, install ChangeDirector onto both nodes using the normal methods and validate that it works just fine by moving the Sql Cluster service through each node. Validate with ChangeDirector that the agent is running correctly.&lt;/p&gt;  &lt;p&gt;Now shut the Service down and modify the configuration file ON EACH NODE. For me the configuration file was on &lt;font face="Consolas" color="#0000ff"&gt;C:\Program Files\Quest Software\Quest Change Director for SQL Server\[SqlClusterName]\QuestChangeTrackerAgent.exe.config&lt;/font&gt;. Update this to point the Trace and Log folders on one of the shared drives used by the cluster. I used the drive dedicated to normally storing dumps and backups onto which kept it away from affecting the other drives in the SAN whilst still making it always available to the cluster.&lt;/p&gt;  &lt;p&gt;Fire up the service again on the active node to verify all is well still then shut it down again and this time change it’s startup type from &lt;font color="#008040"&gt;Automatic&lt;/font&gt; to &lt;font color="#008040"&gt;Manual&lt;/font&gt;.&lt;/p&gt;  &lt;p&gt;Create a new &lt;font color="#008040"&gt;Generic Service&lt;/font&gt; Cluster Resource in the Cluster Administrator. The Service name to use is &lt;font color="#008040"&gt;&lt;strong&gt;Quest Change Tracker Agent&lt;/strong&gt;&lt;/font&gt;. I added a couple of dependencies for both the drive I was using to store the logs and traces on and also Sql Server itself. In addition I elected to change the settings to not affect the group; this way if it should so something daft it wasn’t going to take the whole cluster with it. For me the continuous availability of the cluster trumps ChangeDirector – your individual mileage may, as they oft say, vary. And oh, there are no registry keys to replicate so you don’t need to worry on that front.&lt;/p&gt;  &lt;p&gt;Now you should be able to fire up the resource in the Cluster Administrator and off you go. For a final test move the Sql Cluster through each node verifying that it’s seen by ChangeDirector at all times.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#ff8000"&gt;Windows 2003, ChangeDirector 2.1.0.87&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-6397906117989910917?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/6397906117989910917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/02/clustering-quest-changedirector.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/6397906117989910917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/6397906117989910917'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/02/clustering-quest-changedirector.html' title='Clustering Quest ChangeDirector'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-4634512114035575792</id><published>2009-02-23T07:39:00.001-05:00</published><updated>2009-02-23T08:38:15.564-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Workarounds'/><title type='text'>Unverifiable Passwords with Sql Configuration Manager</title><content type='html'>&lt;p&gt;This was an odd one and much akin to &lt;a href="http://random-thunks.com/2009/01/2005-configuration-manager-oddness.html" target="_blank"&gt;a previous recent incident I’d had with the configuration manager&lt;/a&gt; (albeit this time on a totally different server); this last weekend we had one of our regular ‘let’s all work through the night’ maintenance windows. Such events are never fun to do but made even worse when the strangest of things happen.&lt;/p&gt;  &lt;p&gt;This weekend it was the turn of the Sql Configuration Manager and it’s stubborn refusal to validate a new account password. No matter how many times I tried it would not take the new password, regardless if I pasted it in or typed it in. Each time I’d see an entry in the Security log telling me the attempt to logon with the credentials had failed.&lt;/p&gt;  &lt;p&gt;Given that it was now getting close to 3AM I decided another approach based off the prior experience; I fired up the Services applet and pasted the password directly in there.&lt;/p&gt;  &lt;p&gt;Well, would you Adam and Eve it – it only bloody worked.&lt;/p&gt;  &lt;p&gt;Don’t have a good reason or explanation for this one other than – WTF?&lt;/p&gt;  &lt;p&gt;Still, whatever it takes.&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;Sql Server 2005 SP2 No CR’s.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-4634512114035575792?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/4634512114035575792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/02/unverifiable-passwords-with-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/4634512114035575792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/4634512114035575792'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/02/unverifiable-passwords-with-sql.html' title='Unverifiable Passwords with Sql Configuration Manager'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-8592633830864809249</id><published>2009-02-12T16:14:00.001-05:00</published><updated>2009-02-23T08:33:59.710-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VBA'/><category scheme='http://www.blogger.com/atom/ns#' term='Project'/><category scheme='http://www.blogger.com/atom/ns#' term='TFS'/><category scheme='http://www.blogger.com/atom/ns#' term='Office'/><title type='text'>Maintaining hierarchical names in TFS 2008 from Project 2007</title><content type='html'>&lt;p&gt;Waiting for the nested hierarchical tasks functionality in TFS 2010 is not currently an option for me right now in my quest to process tasks from MS Project 2007. Nor is manually updating each task title within Project to keep some sort of structure since that would be a real pain and be largely un-maintainable once you have more than a few tasks.&lt;/p&gt;  &lt;p&gt;Now it’s been a long while since I last messed around with VBA, so this is probably pretty ugly – however it does do the trick. In addition to keeping the hierarchical naming structure, it also marks summary tasks as not publishable to avoid polluting TFS with them.&lt;/p&gt;  &lt;p&gt;The entry point is &lt;strong&gt;HierarchicalTaskNames()&lt;/strong&gt;.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;TitleStack &lt;span style="color: blue"&gt;As &lt;/span&gt;Collection&lt;br /&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;taskId &lt;span style="color: blue"&gt;As Integer&lt;br /&gt;&lt;br /&gt;Sub &lt;/span&gt;RecursiveScanAndFix(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;t &lt;span style="color: blue"&gt;As &lt;/span&gt;Task)&lt;br /&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;child &lt;span style="color: blue"&gt;As &lt;/span&gt;Task&lt;br /&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;i &lt;span style="color: blue"&gt;As Integer&lt;br /&gt;    Dim &lt;/span&gt;text &lt;span style="color: blue"&gt;As String&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;text = t.Name&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: green"&gt;' If this task has children then add the name to the stack and continue on down&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;t.OutlineChildren.Count &amp;gt; 0 &lt;span style="color: blue"&gt;Then&lt;br /&gt;        &lt;/span&gt;Push(text)&lt;br /&gt;        t.Text25 = &lt;span style="color: #a31515"&gt;&amp;quot;No&amp;quot;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;' Now look for the children&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;For Each &lt;/span&gt;child &lt;span style="color: blue"&gt;In &lt;/span&gt;t.OutlineChildren&lt;br /&gt;            RecursiveScanAndFix(child)&lt;br /&gt;        &lt;span style="color: blue"&gt;Next &lt;/span&gt;child&lt;br /&gt;&lt;br /&gt;        Pop()&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: blue"&gt;Else&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;' No, no children found. So these will be actual tasks. Therefore we need to prepend the hierarchy name onto the task&lt;br /&gt;        ' First off look to see if we've already named this. If so we'll strip the previous hierarchical name off before we start&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;Left(text, 1) = &lt;span style="color: #a31515"&gt;&amp;quot;[&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: green"&gt;' Yes we have. Hunt down the last ] and remove it from the text&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;For &lt;/span&gt;i = Len(text) &lt;span style="color: blue"&gt;To &lt;/span&gt;1 &lt;span style="color: blue"&gt;Step &lt;/span&gt;-1&lt;br /&gt;                &lt;span style="color: blue"&gt;If &lt;/span&gt;Mid(text, i, 1) = &lt;span style="color: #a31515"&gt;&amp;quot;]&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then&lt;br /&gt;                    &lt;/span&gt;text = Mid(text, i + 1)&lt;br /&gt;                    &lt;span style="color: blue"&gt;Exit For&lt;br /&gt;                End If&lt;br /&gt;            Next&lt;br /&gt;            &lt;/span&gt;text = Trim(text)&lt;br /&gt;        &lt;span style="color: blue"&gt;End If&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;' Now add the hierarchical name to the task title&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;t.Name = GetTitleFromStack &amp;amp; &lt;span style="color: #a31515"&gt;&amp;quot; &amp;quot; &lt;/span&gt;&amp;amp; text&lt;br /&gt;&lt;br /&gt;        taskId = t.ID&lt;br /&gt;    &lt;span style="color: blue"&gt;End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Sub &lt;/span&gt;HierarchicalTaskNames()&lt;br /&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;t &lt;span style="color: blue"&gt;As &lt;/span&gt;Task&lt;br /&gt;    taskId = 1&lt;br /&gt;    TitleStack = &lt;span style="color: blue"&gt;New &lt;/span&gt;Collection&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: blue"&gt;While &lt;/span&gt;taskId &amp;lt;= ActiveProject.NumberOfTasks&lt;br /&gt;        t = ActiveProject.Tasks(taskId)&lt;br /&gt;        &lt;span style="color: blue"&gt;If &lt;/span&gt;t.OutlineChildren.Count &amp;gt; 0 &lt;span style="color: blue"&gt;Then&lt;br /&gt;            &lt;/span&gt;RecursiveScanAndFix(ActiveProject.Tasks(taskId))&lt;br /&gt;        &lt;span style="color: blue"&gt;End If&lt;br /&gt;        &lt;/span&gt;taskId = taskId + 1&lt;br /&gt;    &lt;span style="color: blue"&gt;End While&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Function &lt;/span&gt;Pop() &lt;span style="color: blue"&gt;As String&lt;br /&gt;    If &lt;/span&gt;TitleStack.Count &amp;gt; 0 &lt;span style="color: blue"&gt;Then&lt;br /&gt;        &lt;/span&gt;Pop = TitleStack.Item(TitleStack.Count)&lt;br /&gt;        TitleStack.Remove(TitleStack.Count)&lt;br /&gt;    &lt;span style="color: blue"&gt;End If&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;Function &lt;/span&gt;Push(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;Title &lt;span style="color: blue"&gt;As String&lt;/span&gt;)&lt;br /&gt;    TitleStack.Add(Title)&lt;br /&gt;&lt;span style="color: blue"&gt;End Function&lt;br /&gt;&lt;br /&gt;Function &lt;/span&gt;GetTitleFromStack() &lt;span style="color: blue"&gt;As String&lt;br /&gt;    &lt;/span&gt;GetTitleFromStack = &lt;span style="color: #a31515"&gt;&amp;quot;[ &amp;quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;i &lt;span style="color: blue"&gt;As Integer&lt;br /&gt;&lt;br /&gt;    For &lt;/span&gt;i = 1 &lt;span style="color: blue"&gt;To &lt;/span&gt;TitleStack.Count&lt;br /&gt;        GetTitleFromStack = GetTitleFromStack &amp;amp; TitleStack.Item(i)&lt;br /&gt;        &lt;span style="color: blue"&gt;If &lt;/span&gt;i &amp;lt;&amp;gt; TitleStack.Count &lt;span style="color: blue"&gt;Then&lt;br /&gt;            &lt;/span&gt;GetTitleFromStack = GetTitleFromStack &amp;amp; &lt;span style="color: #a31515"&gt;&amp;quot; | &amp;quot;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;End If&lt;br /&gt;    Next&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;GetTitleFromStack = GetTitleFromStack &amp;amp; &lt;span style="color: #a31515"&gt;&amp;quot; ]&amp;quot;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;MS Project 2007 SP1&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-8592633830864809249?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/8592633830864809249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/02/maintaining-hierarchical-names-in-tfs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8592633830864809249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8592633830864809249'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/02/maintaining-hierarchical-names-in-tfs.html' title='Maintaining hierarchical names in TFS 2008 from Project 2007'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-3014553828261053528</id><published>2009-02-10T13:54:00.001-05:00</published><updated>2009-02-27T17:52:00.324-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiX'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Wix Rollin’</title><content type='html'>&lt;p&gt;What a difference a few hours makes. Yesterday afternoon I was feeling mightily peeved off that Microsoft had still not put any support in MSBuild for building Visual Studio Deployment Projects. I was with the folks in the various forums, blogs and other dark places where we all visit who cried ‘foul!’ and ‘unfair’ and MS’s decision.&lt;/p&gt;  &lt;p&gt;That was however until I rediscovered &lt;a href="http://wix.sourceforge.net/" target="_blank"&gt;WiX – Windows Installer XML&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I had seen WiX once before (quite some time before) and at the time I dismissed it as ‘Something I might care about later’. My TFS Build at the time were creating libraries or other code that didn’t required an installer so I really paid it no heed. Well, yesterday was the day that I cared about it.&lt;/p&gt;  &lt;p&gt;MS obviously have put a lot of faith in WiX – I read somewhere that they even use it internally to build the Office 2007 installer – if this is indeed the case then it’s no small feat. The installers I needed to create where by no-means on the same level so I figured at that time, when in Rome.&lt;/p&gt;  &lt;p&gt;Now granted WiX is a bit of a learning curve but there are tools out there that make your life easy – especially when you’ve already got a .vdproj that you need to WiXify. When converting existing deployment projects there’s a slight reverse around face in that it actually makes more sense to start with the end-project and work your way back to a new installer than attempt to build a new WiX project from scratch.&lt;/p&gt;  &lt;p&gt;So, in an attempt to help clarify a few steps, here’s my trip down converting an existing deployment project into a new fangled WiX project – complete with the need to reference binaries as part of the MS Enterprise Application block 4.1. &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;Caveat Emptor: I’m not saying that these steps are the most efficient – however they did work for me!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="1"&gt;NB: I was using the WiX Beta 3 build 4805.0 to create my packages and Visual Studio 2008 Team Suite along with TFS 2008 to create my projects and builds.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 1: Reverse engineer to deployment project.&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Sure you have the source, so why reverse engineer anything? Well, in our case the project builds an MSI file which is pretty easy to decompile given the tools available in WiX. So, first off copy the MSI to a temporary work area and execute the Dark WiX executable to decompile the MSI into it’s constituent parts – and create a WiX project file as a result.&lt;/p&gt;  &lt;table border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;pre&gt;&lt;font size="1"&gt;&lt;b&gt;&lt;span style="color: rgb(0,0,160)"&gt;C:\tmp\1 Day\WiX&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style="color: rgb(164,0,0)"&gt;&amp;quot;C:\Program Files\Windows Installer XML v3\bin\dark.exe&amp;quot; -x Binary LogProcessorServiceSetup.msi LogProcessorServiceSetup.Wxs&lt;/span&gt;&lt;/i&gt;&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;        &lt;pre&gt;&lt;font size="1"&gt;&lt;span style="color: rgb(164,0,0)"&gt;&lt;font color="#000000"&gt;Microsoft (R) Windows Installer Xml Decompiler version 3.0.4805.0&lt;/font&gt;&lt;/span&gt;&lt;br /&gt;Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;&lt;br /&gt;LogProcessorServiceSetup.msi&lt;br /&gt;C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1060 : The _VsdLaunchCondition table is being decompiled as a custom table.dark.exe : warning DARK1065 : The AdvtUISequence table is not supported by the WiX toolset because it has been deprecated by the Windows Installer team.  Any information in this table will be left out of the decompiled output.&lt;br /&gt;C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1062 : The ModuleSignature table can only be represented in WiX for merge modules.  The information in this table will be left out of the decompiled output.&lt;br /&gt;C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1062 : The ModuleComponents table can only be represented in WiX for merge modules.  The information in this table willbe left out of the decompiled output.&lt;br /&gt;C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1066 : The MsiPatchHeaders table is added to the install package by a transform from a patch package (.msp) and not authored directly into an install package (.msi). The information in this table will be left out of the decompiled output.C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1066 : The Patch table is added to the install package by a transform from a patch package (.msp) and not authored directly into an install package (.msi). The information in this table will be left out of the decompiled output.C:\tmp\1 Day\WiX\LogProcessorServiceSetup.msi : warning DARK1066 : The PatchPackage table is added to the install package by a transform from a patch package (.msp) and not authored directly into an install package (.msi). The information in this table will be left out of the decompiled output.dark.exe : warning DARK1058 : The AdvtExecuteSequence table contains an action 'MsiUnpublishAssemblies' which is not allowed in this table.  If this is a standard action then it is not valid for this table, if it is a custom action or dialog then this table does not accept actions of that type.  This action will be left out of the decompiled output.&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(0,0,160)"&gt;C:\tmp\1 Day\WiX&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;/td&gt;&lt;br /&gt;    &lt;/tr&gt;&lt;br /&gt;  &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Getting a directory listing gives us the output of the decompilation process.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;br /&gt;    &lt;tr&gt;&lt;br /&gt;      &lt;td&gt;&lt;br /&gt;        &lt;pre&gt;&lt;font size="1"&gt;&lt;b&gt;&lt;span style="color: rgb(0,0,160)"&gt;C:\tmp\1 Day\WiX&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style="color: rgb(164,0,0)"&gt;dir /s&lt;/span&gt;&lt;/i&gt;&lt;br /&gt; Volume in drive C has no label.&lt;br /&gt; Volume Serial Number is 045E-5666&lt;br /&gt;&lt;br /&gt; Directory of C:\tmp\1 Day\WiX&lt;br /&gt;&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          .&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          ..&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          Binary&lt;br /&gt;02/10/2009  10:36 AM           434,688 LogProcessorServiceSetup.msi&lt;br /&gt;02/10/2009  10:39 AM            91,008 LogProcessorServiceSetup.Wxs&lt;br /&gt;               2 File(s)        525,696 bytes&lt;br /&gt;&lt;br /&gt; Directory of C:\tmp\1 Day\WiX\Binary&lt;br /&gt;&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          .&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          ..&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          Binary&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          File&lt;br /&gt;               0 File(s)              0 bytes&lt;br /&gt;&lt;br /&gt; Directory of C:\tmp\1 Day\WiX\Binary\Binary&lt;br /&gt;&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          .&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          ..&lt;br /&gt;02/10/2009  10:39 AM             5,088 DefBannerBitmap&lt;br /&gt;02/10/2009  10:39 AM            65,032 InstallUtil&lt;br /&gt;02/10/2009  10:39 AM           227,832 MSVBDPCADLL&lt;br /&gt;02/10/2009  10:39 AM               318 NewFldrBtn&lt;br /&gt;02/10/2009  10:39 AM               318 UpFldrBtn&lt;br /&gt;02/10/2009  10:39 AM            11,225 VSDNETCFG&lt;br /&gt;               6 File(s)        309,813 bytes&lt;br /&gt;&lt;br /&gt; Directory of C:\tmp\1 Day\WiX\Binary\File&lt;br /&gt;&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          .&lt;br /&gt;02/10/2009  10:39 AM    &amp;lt;DIR&amp;gt;          ..&lt;br /&gt;02/10/2009  10:36 AM             7,680 _0A137FFDF05A958D558EC9E2DC48F39A&lt;br /&gt;02/06/2009  07:48 AM             1,326 _2CB35E650D766290C1E57911DE7343FA&lt;br /&gt;02/10/2009  10:36 AM             9,216 _35C91406817D7569FFBF7DDCC6ADDC59&lt;br /&gt;02/10/2009  10:35 AM            13,312 _4EE2E5745FE6A5B237002FB1A0E247F1&lt;br /&gt;02/10/2009  10:36 AM            13,312 _517D39ACB53634B59852C8E153B41E98&lt;br /&gt;02/10/2009  10:35 AM            16,384 _6C0EF8CC468814B88806785D8F531905&lt;br /&gt;02/10/2009  10:35 AM            10,240 _7D696D868B909DC126A1AB2EDED8BEE1&lt;br /&gt;02/10/2009  10:35 AM            10,240 _933F30ADC0DFD69EB551623235879B21&lt;br /&gt;02/10/2009  10:36 AM            14,336 _C91E465D8BB437D741ED4B41A36F6385&lt;br /&gt;               9 File(s)         96,046 bytes&lt;br /&gt;&lt;br /&gt;     Total Files Listed:&lt;br /&gt;              17 File(s)        931,555 bytes&lt;br /&gt;              11 Dir(s)  18,724,569,088 bytes free&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: rgb(0,0,160)"&gt;C:\tmp\1 Day\WiX&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;i&gt;&lt;span style="color: rgb(164,0,0)"&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;/td&gt;&lt;br /&gt;    &lt;/tr&gt;&lt;br /&gt;  &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The Files under &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Binary\File&lt;/strong&gt;&lt;/font&gt; are the actual DLL’s etc that have been packaged up and as such can be safely disposed of (we have the originals still available to us within the VS Solution. &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Binary\Binary&lt;/strong&gt;&lt;/font&gt; contains the various support files that are required to run the installer. Note that the files have no extension – that’s perfectly fine and can be left as is.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 2: Create a new WiX project in the solution.&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;WiX comes with a few bonus tracks; one of which is Votive. Votive is essentially a WiX project type for Visual Studio and gives you not only the ability to edit the files utilizing IntelliSense, but to set up project properties as well.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="299" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Once built, you should see something akin to the following in your Solution Explorer window:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_3.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="91" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_3.png" width="240" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;First thing we need to do is gut the created &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Product.Wxs&lt;/strong&gt;&lt;/font&gt; and replace it with the one &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Dark.exe&lt;/strong&gt;&lt;/font&gt; generated for us. Make sure the &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Product.Wxs&lt;/strong&gt;&lt;/font&gt; file is open in the VS Editor then paste the text straight in, overwriting everything.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 3: Update the support binaries&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you examine the newly pasted content you’ll come across the first area that we need to address; the support files are currently in the wrong location.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_4.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="102" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_4.png" width="640" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To resolve this, create a new &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Binary&lt;/strong&gt;&lt;/font&gt; folder in the project and copy the contents &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Binary\Binary&lt;/strong&gt;&lt;/font&gt; folder over to the solution then update the &lt;strong&gt;&lt;font color="#ff0000"&gt;SourceFile&lt;/font&gt;&lt;/strong&gt; values accordingly:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_5.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="122" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_5.png" width="640" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;Step 4: Update the package files&lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We’re getting close now – however we still don’t yet have something that will build correctly for the simple reason the references are shot. So they will need to be updated next.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Take a look further down the Wxs file and you’ll come across the area of concern:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_6.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="274" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_6.png" width="640" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You’ll notice that the &lt;font color="#ff0000"&gt;&lt;strong&gt;Source&lt;/strong&gt;&lt;/font&gt; value is set to a GUID that refers back to one of the files we threw away after executing &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Dark.exe&lt;/strong&gt;&lt;/font&gt;. Fortunately we don’t need to translate the filename as it’s provided for us is the &lt;font color="#ff0000"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/font&gt; value. All we need to do here then is replace the folder name and file with a relative path where we’re taking the files from. In my case here I stored the DLL’s used in a folder called &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Common\Bin&lt;/strong&gt;&lt;/font&gt;. So one of my entries would now look like:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_14.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="62" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_14.png" width="640" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;Step 5: Referencing external libraries&lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;That takes care of our files, but what of other external files – in my case use of the Enterprise Application Block. In order to make the build transparent across both Visual Studio and TFS I needed a better route of referencing the correct binaries. This is where the use of a Preprocessor directive comes into play.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Open up the WiX project properties and select the ‘All Configurations’ configuration:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_8.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="170" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_8.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The Enterprise Application 4.1 block always installs itself into &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;%ProgramFiles\Microsoft Enterprise Library 4.1 - October 2008&lt;/strong&gt;&lt;/font&gt; so we can use that to create our variable. Enter the following in the first text box (Preprocessor variables):&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Consolas" color="#008000"&gt;&lt;strong&gt;MSEntBlock41=$(ProgramFiles)\Microsoft Enterprise Library 4.1 - October 2008\Bin&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Since VS 2008 (like 2005) uses MSBuild behind the scenes, this will expand to reference the correct location. By using an environment variable we avoid situations where the C: drive may not the the default drive on the build server.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now we need to simply reference this Preprocessor variable in the Wxs script using the form &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;$(var.MSEntBlock41)&lt;/strong&gt;&lt;/font&gt;:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_9.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="80" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_9.png" width="745" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 6: Dealing with the registry&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whilst the Wxs generated by &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Dark.exe&lt;/strong&gt;&lt;/font&gt; is valid, it apparently does not meet it’s own standards – namely registry access.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For example, here’s what &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;Dark.exe&lt;/strong&gt;&lt;/font&gt; generated:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_10.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="62" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_10.png" width="800" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;However the correct format required is:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_11.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="70" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_11.png" width="806" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Notice the use of a referencing the &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;windir&lt;/strong&gt;&lt;/font&gt; environment variable. We could have used a Preprocessor variable here as well – I simply wanted to demonstrate using both sorts.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 7: App.Config&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The final change we need to make is to reference the applications &lt;font face="Consolas" color="#008040"&gt;&lt;strong&gt;App.config&lt;/strong&gt;&lt;/font&gt; file. Normally the deployment project handles this transformation for us but we need to perform the step via WiX. However it’s easy enough:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_12.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="54" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_12.png" width="800" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;&lt;font color="#ff0000" size="3"&gt;&lt;strong&gt;Step 8: Updating the build configuration&lt;/strong&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The final step required is to ensure TFS Build picks up the new project. The set up projects created by WiX seem to target Chipsets; as a result I had to update the Configuration Manager to ensure that they were included in a ‘Any CPU’ build. This is probably not best practice but will work for me (your mileage may vary) &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WixRollin_939C/image_13.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="260" alt="image" src="http://attachments.random-thunks.com/WixRollin_939C/image_thumb_13.png" width="404" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;font color="#ff0000" size="3"&gt;Further reading:&lt;/font&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;WiX Tutorial : &lt;a title="http://www.tramontana.co.hu/wix/" href="http://www.tramontana.co.hu/wix/"&gt;http://www.tramontana.co.hu/wix/&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Preprocessor variables: &lt;a title="http://wix.sourceforge.net/manual-wix2/preprocessor.htm" href="http://wix.sourceforge.net/manual-wix2/preprocessor.htm"&gt;http://wix.sourceforge.net/manual-wix2/preprocessor.htm&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;WiX v3.4805.0, TFS 2008 SP1, VS 2008 SP1&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-3014553828261053528?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/3014553828261053528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/02/wix-rollin.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3014553828261053528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3014553828261053528'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/02/wix-rollin.html' title='Wix Rollin’'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-2487434876791632139</id><published>2009-01-28T14:29:00.001-05:00</published><updated>2009-02-02T07:48:08.462-05:00</updated><title type='text'>Locating Signed Procedures in Sql Server</title><content type='html'>&lt;p&gt;I recently had to redeploy a DB on another server with a whole new master key. This meant that I had to destroy and recreate all the existing Certificates and Keys that I’d created based off the previous master key.&lt;/p&gt;  &lt;p&gt;The biggest problem for me was locating all the pesky procedures that I’d signed previously that would need to be resigned with a new certificate; however locating this took a bit of time. Eventually I was able to come up with the following query:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="635" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="43"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="590"&gt;         &lt;pre class="code"&gt;&lt;font face="Consolas"&gt;&lt;span style="color: blue"&gt;Select    &lt;/span&gt;&lt;span style="color: magenta"&gt;Schema_Name&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;O&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: magenta"&gt;schema_id&lt;/span&gt;&lt;span style="color: gray"&gt;) + &lt;/span&gt;&lt;span style="color: red"&gt;'.' &lt;/span&gt;&lt;span style="color: gray"&gt;+ &lt;/span&gt;&lt;span style="color: magenta"&gt;Object_Name&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;Cp&lt;span style="color: gray"&gt;.&lt;/span&gt;major_id&lt;span style="color: gray"&gt;) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: red"&gt;'Module'&lt;br /&gt;         &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;cp&lt;span style="color: gray"&gt;.&lt;/span&gt;crypt_type_desc &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: red"&gt;'Method'&lt;br /&gt;         &lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: magenta"&gt;Coalesce&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;C&lt;span style="color: gray"&gt;.&lt;/span&gt;name&lt;span style="color: gray"&gt;, &lt;/span&gt;AK&lt;span style="color: gray"&gt;.&lt;/span&gt;name&lt;span style="color: gray"&gt;) &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: red"&gt;'Signing Object'&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;From      &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;crypt_properties &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;Cp&lt;br /&gt;    &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: green"&gt;-- Get the schema&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: gray"&gt;Inner Join    &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;objects &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;O&lt;br /&gt;        &lt;span style="color: blue"&gt;On &lt;/span&gt;O&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: magenta"&gt;object_id &lt;/span&gt;&lt;span style="color: gray"&gt;= &lt;/span&gt;Cp&lt;span style="color: gray"&gt;.m&lt;/span&gt;ajor_id&lt;br /&gt;    &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: green"&gt;-- Asymmetric Key (if any)&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: gray"&gt;Left Join     &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;asymmetric_keys &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;Ak&lt;br /&gt;        &lt;span style="color: blue"&gt;On &lt;/span&gt;Ak&lt;span style="color: gray"&gt;.&lt;/span&gt;thumbprint &lt;span style="color: gray"&gt;= &lt;/span&gt;Cp&lt;span style="color: gray"&gt;.&lt;/span&gt;thumbprint&lt;br /&gt;    &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color: green"&gt;-- Ceritificate (if any)&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: gray"&gt;Left Join     &lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;certificates &lt;/span&gt;&lt;span style="color: blue"&gt;As &lt;/span&gt;C&lt;br /&gt;        &lt;span style="color: blue"&gt;On &lt;/span&gt;C&lt;span style="color: gray"&gt;.&lt;/span&gt;thumbprint &lt;span style="color: gray"&gt;= &lt;/span&gt;Cp&lt;span style="color: gray"&gt;.&lt;/span&gt;thumbprint&lt;/font&gt;&lt;/pre&gt;&lt;br /&gt;      &lt;/td&gt;&lt;br /&gt;    &lt;/tr&gt;&lt;br /&gt;  &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-2487434876791632139?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/2487434876791632139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/01/locating-signed-procedures-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2487434876791632139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2487434876791632139'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/01/locating-signed-procedures-in-sql.html' title='Locating Signed Procedures in Sql Server'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-253302730420340789</id><published>2009-01-20T08:44:00.001-05:00</published><updated>2009-01-20T08:44:00.993-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Workarounds'/><category scheme='http://www.blogger.com/atom/ns#' term='Odd'/><category scheme='http://www.blogger.com/atom/ns#' term='Integration Services'/><title type='text'>2005 Configuration manager oddness</title><content type='html'>&lt;p&gt;I was doing a round of mass service account password changes today on one of our development servers and came across this bit of strangeness; despite making several attempts to update the account and password in the Configuration manager the SSIS service refused not only to start up, but also failed to give any indication as to why (the application logs were horribly silent on anything from either SSIS or even the service manager).&lt;/p&gt;  &lt;p&gt;So I went into the back door and fired up the Services applet and refreshed the password in there. One message informing me the account had been granted the ‘Logon as a service’ privilege and the service was up.&lt;/p&gt;  &lt;p&gt;What beats me is why the configuration manager refused on multiple times to accept the change. Not saying we should all ignore the config manager from now on but I myself will bear this in mind for future weirdness.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-253302730420340789?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/253302730420340789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/01/2005-configuration-manager-oddness.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/253302730420340789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/253302730420340789'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/01/2005-configuration-manager-oddness.html' title='2005 Configuration manager oddness'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-1083781051140435636</id><published>2009-01-02T13:11:00.001-05:00</published><updated>2009-01-02T13:12:16.968-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DR'/><title type='text'>A tough lesson to learn</title><content type='html'>&lt;p&gt;Apparently &lt;a href="http://journalspace.com/" target="_blank"&gt;JournalSpace.com&lt;/a&gt; has learned the lesson of an what happens when you don’t have an effective disaster recovery strategy the hard way. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://attachments.random-thunks.com/Atoughlessontolearn_B964/image.png"&gt;&lt;img title="JournalSpace.com message" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="JournalSpace.com message" src="http://attachments.random-thunks.com/Atoughlessontolearn_B964/image_thumb.png" width="503" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Using OS X as a operating System - $1998, Employing a technician who knows a thing or two about backups, $65,000. Not using mirroring as a backup process - Priceless. Life needs tapes. For everything else there is unemployment.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-1083781051140435636?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/1083781051140435636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2009/01/tough-lesson-to-learn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1083781051140435636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/1083781051140435636'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2009/01/tough-lesson-to-learn.html' title='A tough lesson to learn'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-8076720045977679828</id><published>2008-12-23T14:20:00.001-05:00</published><updated>2008-12-23T15:07:46.055-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Service Packs'/><title type='text'>And hot on the heels of 2005 SP3 comes…</title><content type='html'>&lt;p&gt;Cumulative Rollup 1 which essentially comprises CUs’ 10 and 11 for SP2.&lt;/p&gt;  &lt;p&gt;In the good old days would MS just release something akin to a SP3a? Ah well..&lt;/p&gt;  &lt;p&gt;Service pack 3 is &lt;a href="http://go.microsoft.com/fwlink/?LinkId=135960" target="_blank"&gt;here&lt;/a&gt;, CU1 is &lt;a href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=959195&amp;amp;kbln=en-us" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-8076720045977679828?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/8076720045977679828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2008/12/and-hot-on-heels-of-2005-sp3-comes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8076720045977679828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8076720045977679828'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2008/12/and-hot-on-heels-of-2005-sp3-comes.html' title='And hot on the heels of 2005 SP3 comes…'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-66146261114212585</id><published>2008-12-18T09:12:00.001-05:00</published><updated>2008-12-18T09:13:29.447-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Service Packs'/><title type='text'>Sql Server 2005 SP3 released!</title><content type='html'>&lt;p&gt;Microsoft have finally released &lt;a href="http://support.microsoft.com/kb/913089/"&gt;Sql Server 2005 SP3&lt;/a&gt; – how long was that chaps? 1.2 eternities or 1.3? (I lost track after a few lifetimes).&lt;/p&gt;  &lt;p&gt;Well, better late than never, least now I don’t need to grab the less supported CRs to get the latest round of &lt;a href="http://support.microsoft.com/?kbid=955706"&gt;fixes&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-66146261114212585?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/66146261114212585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2008/12/ss2005-sp3-released-no-more-2005-crs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/66146261114212585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/66146261114212585'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2008/12/ss2005-sp3-released-no-more-2005-crs.html' title='Sql Server 2005 SP3 released!'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-5044256334320285373</id><published>2008-12-16T08:45:00.001-05:00</published><updated>2008-12-16T13:00:37.485-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><title type='text'>Management Studio folders</title><content type='html'>&lt;p&gt;What MS giveth with one hand they unceremoniously forget to supply with the other; here I’m referring to being able to update the path of the folders used by Management Studio for storing projects etc.&lt;/p&gt;  &lt;p&gt;Fortunately it’s an easy fix that, as usual, relies on the registry.&lt;/p&gt;  &lt;p&gt;Fire up &lt;font color="#008000"&gt;regedit&lt;/font&gt; (or your favorite registry hacker) and move yourself to&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas" color="#0000ff"&gt;HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;and update the folder paths there.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-5044256334320285373?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/5044256334320285373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2008/12/management-studio-folders.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/5044256334320285373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/5044256334320285373'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2008/12/management-studio-folders.html' title='Management Studio folders'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-9073755245610311682</id><published>2008-12-16T08:40:00.001-05:00</published><updated>2008-12-16T08:40:34.717-05:00</updated><title type='text'>Still here!</title><content type='html'>&lt;p&gt;Good lord, you know when you’re getting old when over a year zips past you and it feels like yesterday…&lt;/p&gt;  &lt;p&gt;Things have gotten a wee broken here and there – lost my images for one and my Worldview has up and left me. Time to do some maintenance work and clean things up again and get everything all ship-shape &amp;amp; Bristol fashion.&lt;/p&gt;  &lt;p&gt;In the meantime…&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-9073755245610311682?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/9073755245610311682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2008/12/still-here.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/9073755245610311682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/9073755245610311682'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2008/12/still-here.html' title='Still here!'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-2081561648793370243</id><published>2007-10-19T19:37:00.001-04:00</published><updated>2007-10-19T19:37:07.456-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TFS'/><title type='text'>...or just wait for TFS 2008</title><content type='html'>&lt;p&gt;Looks like TFS 2008 comes with the ability to permanently destroy SCC files via the command line. Also included with 2008 is the ability to create Continuous Integration Builds on Team Build right out of the box - no more do you need to customize TFS to allow that. All in all, 2008 sounds like it's a big step in the right direction.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-2081561648793370243?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/2081561648793370243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/10/or-just-wait-for-tfs-2008.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2081561648793370243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2081561648793370243'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/10/or-just-wait-for-tfs-2008.html' title='...or just wait for TFS 2008'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-2818788122266302094</id><published>2007-10-16T15:21:00.001-04:00</published><updated>2007-10-16T15:23:18.044-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TFS'/><title type='text'>Permanently deleting files from TFS Source Code Control</title><content type='html'>&lt;p&gt;Not for the fainthearted this so continue with absolute caution - usual disclaimers apply most least don't blame me if you loose your entire TFS implementation, TFS Server and most of the rest of your development universe...&lt;/p&gt; &lt;p&gt;So, you're deleted a project from TFS using the &lt;font face="Consolas" color="#008040"&gt;TFSDeleteProject&lt;/font&gt; CLI command but still have crud left hanging around, taking up space or worse - still showing up if you recreate a project with the same name. The &lt;font face="Consolas" color="#008040"&gt;TFSDeleteProject&lt;/font&gt; command by nature will not delete much of anything - it simply marks a project as unused and moves it from &lt;font face="Consolas" color="#0000ff"&gt;TfsIntegration.dbo.tbl_projects&lt;/font&gt; to &lt;font face="Consolas" color="#0000ff"&gt;TfsIntegration.dbo.projects_tombstone&lt;/font&gt; (among other actions). As a result you're still left with a potentially large DB filled with useless crud.&lt;/p&gt; &lt;p&gt;Files in TFS SCC are located in three tables in the &lt;font face="Consolas" color="#0000ff"&gt;tfsVersionControl&lt;/font&gt; database: &lt;font face="Consolas" color="#0000ff"&gt;dbo.tbl_NameSpace&lt;/font&gt;, &lt;font face="Consolas" color="#0000ff"&gt;dbo.tbl_File&lt;/font&gt; and &lt;font face="Consolas" color="#0000ff"&gt;dbo.tbl_Content&lt;/font&gt;.&lt;/p&gt; &lt;p&gt;The root table is &lt;font face="Consolas" color="#0000ff"&gt;tbl_NameSpace&lt;/font&gt; - this table provides the full path to the object along with an &lt;font face="Consolas" color="#0000ff"&gt;ItemId&lt;/font&gt;. This &lt;font face="Consolas" color="#0000ff"&gt;ItemId&lt;/font&gt; is used to key into the &lt;font face="Consolas" color="#0000ff"&gt;tbl_Files&lt;/font&gt; table which yields a &lt;font face="Consolas" color="#0000ff"&gt;FileId&lt;/font&gt; that joins up with &lt;font face="Consolas" color="#0000ff"&gt;tbl_Content&lt;/font&gt;.&lt;/p&gt; &lt;p&gt;You'll want to carefully identify which items from &lt;font face="Consolas" color="#0000ff"&gt;tbl_Namespace&lt;/font&gt; you want to wipe out and removes the corresponding entries from the other two tables.&lt;/p&gt; &lt;p&gt;Backup your database first and make sure you've a sacrificial chicken on hand just in case...&lt;em&gt;And did I happen to mention you should back up your database first...?&lt;/em&gt;&lt;/p&gt; &lt;p&gt;I'm sure there are some other tables out there affected by this but these appear to be the main three.&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-2818788122266302094?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/2818788122266302094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/10/permanently-deleting-files-from-tfs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2818788122266302094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/2818788122266302094'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/10/permanently-deleting-files-from-tfs.html' title='Permanently deleting files from TFS Source Code Control'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-403961340039821853</id><published>2007-08-01T09:03:00.001-04:00</published><updated>2007-08-01T09:04:46.676-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ContentType'/><category scheme='http://www.blogger.com/atom/ns#' term='MOSS'/><title type='text'>When True != True</title><content type='html'>&lt;p&gt;Content Types were giving me a hard time recently, most specifically in trying to hide/show columns in a content type in a custom list/document library.&lt;/p&gt; &lt;p&gt;Handy hint to know here folks: The only valid values for True or False appear to be TRUE or FALSE. Anything else seems to be interpreted based on any number of seemingly random factors...&lt;/p&gt; &lt;p&gt;For example, this is now valid:&lt;/p&gt; &lt;p&gt;&lt;a href="http://attachments.random-thunks.com/WhenTrueTrue_7E58/image.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="135" alt="image" src="http://attachments.random-thunks.com/WhenTrueTrue_7E58/image_thumb.png" width="640" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-403961340039821853?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/403961340039821853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/08/when-true-true.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/403961340039821853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/403961340039821853'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/08/when-true-true.html' title='When True != True'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-8580739418585877100</id><published>2007-08-01T08:55:00.001-04:00</published><updated>2007-08-01T08:55:22.502-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql Server'/><category scheme='http://www.blogger.com/atom/ns#' term='Katmai'/><title type='text'>Katmai July CTP is out!</title><content type='html'>&lt;p&gt;And with it comes a few new features including the final arrival of separate DATE and TIME datatypes and the ability for Mirrored system to perform page page repair by taking corrupted pages from the mirror.&lt;/p&gt; &lt;p&gt;I'm really begging to like the look and feel of 2008 now.&lt;/p&gt; &lt;p&gt;A full list of new features can be found &lt;a title="https://connect.microsoft.com/SQLServer/content/content.aspx?ContentID=5470" href="https://connect.microsoft.com/SQLServer/content/content.aspx?ContentID=5470"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-8580739418585877100?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/8580739418585877100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/08/katmai-july-ctp-is-out.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8580739418585877100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/8580739418585877100'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/08/katmai-july-ctp-is-out.html' title='Katmai July CTP is out!'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-3621848436858147176</id><published>2007-07-23T11:25:00.001-04:00</published><updated>2007-07-23T11:28:02.439-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Vista ++ ==  ?</title><content type='html'>&lt;p&gt;Hot on the heels of such illustrious internal code names such as &lt;font color="#0000ff"&gt;&lt;strong&gt;Yukon&lt;/strong&gt;&lt;/font&gt;, &lt;font color="#0000ff"&gt;&lt;strong&gt;Avalon&lt;/strong&gt;&lt;/font&gt;, &lt;strong&gt;&lt;font color="#0000ff"&gt;Chicago&lt;/font&gt;&lt;/strong&gt;, &lt;font color="#0000ff"&gt;&lt;strong&gt;Cairo&lt;/strong&gt;&lt;/font&gt;, &lt;font color="#0000ff"&gt;&lt;strong&gt;Katmai&lt;/strong&gt;&lt;/font&gt; and &lt;strong&gt;&lt;font color="#0000ff"&gt;Whidbey&lt;/font&gt;&lt;/strong&gt; (along with such lesser known luminaries such as &lt;strong&gt;&lt;font color="#0000ff"&gt;Mönch&lt;/font&gt;&lt;/strong&gt; and &lt;font color="#0000ff"&gt;&lt;strong&gt;Yamazaki&lt;/strong&gt;&lt;/font&gt;), comes the latest code name out of Redmond for Vista (&lt;font color="#0000ff"&gt;&lt;strong&gt;Longhorn&lt;/strong&gt;&lt;/font&gt;)’s replacement due in three years time. Gone are the names from the Whistler-Blackcomb resort (e.g. &lt;font color="#0000ff"&gt;&lt;strong&gt;Freestyle&lt;/strong&gt;&lt;/font&gt; and &lt;font color="#0000ff"&gt;&lt;strong&gt;Harmony&lt;/strong&gt;&lt;/font&gt;) or place names around the hallowed Seattle (e.g. &lt;font color="#0000ff"&gt;&lt;strong&gt;Rainier&lt;/strong&gt;&lt;/font&gt;, &lt;font color="#0000ff"&gt;&lt;strong&gt;Everett&lt;/strong&gt;&lt;/font&gt; and &lt;font color="#0000ff"&gt;&lt;strong&gt;Orcas&lt;/strong&gt;&lt;/font&gt;) or rather abstract names such as &lt;font color="#0000ff"&gt;&lt;strong&gt;Godot&lt;/strong&gt;&lt;/font&gt; (from the play “Waiting for Godot”) and &lt;font color="#0000ff"&gt;&lt;strong&gt;Darwin&lt;/strong&gt;&lt;/font&gt;. Nope, the internal marketing team have gone all out for the next version of the world’s most used O/S. &lt;p&gt;And just what have this mighty team of highly experienced folk decided to call this next incarnation of the Linux and OS/X beater – surely a name that symbolizes strength or purpose, or perhaps something more natural to represent simplistic strength, or perhaps the name of a city that symbolizes mankind's innate ability to overcome obstacles? &lt;p&gt;For all those who answered “Vienna” then sorry – you’re now wrong. Nope, apparently it’s new code name is “7”. Impressive huh? &lt;p&gt;Interestingly enough I think this answers one or two questions I had about workflow…. &lt;p&gt;&lt;a title="http://news.com.com/Next+version+of+Windows+Call+it+7/2100-1016_3-6197943.html" href="http://news.com.com/Next+version+of+Windows+Call+it+7/2100-1016_3-6197943.html"&gt;http://news.com.com/Next+version+of+Windows+Call+it+7/2100-1016_3-6197943.html&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-3621848436858147176?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/3621848436858147176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/07/vista.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3621848436858147176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/3621848436858147176'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/07/vista.html' title='Vista ++ ==  ?'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31397272.post-4827792007437276752</id><published>2007-06-27T21:03:00.001-04:00</published><updated>2007-06-27T21:34:00.778-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Forms Services'/><category scheme='http://www.blogger.com/atom/ns#' term='InfoPath'/><category scheme='http://www.blogger.com/atom/ns#' term='MOSS'/><category scheme='http://www.blogger.com/atom/ns#' term='Grumbles'/><title type='text'>What you mean 'not found'?</title><content type='html'>&lt;p&gt;Stupid, stupid, stupid.&lt;/p&gt; &lt;p&gt;You can either apply that to me thinking that attaching a file to my InfoPath task form would be easy or MS for allowing such a nasty insidious bug to crawl out into production.&lt;/p&gt; &lt;p&gt;Here's the issue. I have an InfoPath&amp;nbsp;task form running under MOSS Enterprise forms services. Upon this form I have a couple of file attachment controls. One would thunk that given that file attachment controls seem to have been a part of HTML since the mid 1990's (&lt;a title="http://www.faqs.org/rfcs/rfc1867.html" href="http://www.faqs.org/rfcs/rfc1867.html"&gt;RFC 1867&lt;/a&gt;) that this should be a totally elementary operation.&lt;/p&gt; &lt;p&gt;Heh, think again.&lt;/p&gt; &lt;p&gt;I found this out the hard way when, after browsing to my file and pressing the Upload button I was met with a rather curt 'The Selected File was not found' error message. A hunt around the blogsphere bore only one low dangling fruit : &lt;a href="http://chrissyblanco.blogspot.com/2006/07/workflow-that-uploads-document-via.html"&gt;A WorkFlow that Uploads a Document via a Task using an InfoPath Form&lt;/a&gt;. which I gave&amp;nbsp;a try but to no avail.&lt;/p&gt; &lt;p&gt;Turns out the author was 99.9998% there - except for the the direction of one slash! So, rather than regurgitate the entire post, here's the correct JavaScript segment you need:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Consolas"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aspnetForm.encoding = "multipart/form-data";&lt;br&gt;&amp;lt;/script&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;However, when all's said and done I have to ask the question, why? Why do we have to slice up the &lt;strong&gt;&lt;em&gt;&lt;font color="#008000"&gt;WkTaskIP.aspx&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt; page to add this functionality in? I guess tomorrow I'll be one the ole Dog n' Bone to MS PSS to pursue this one further.&lt;/p&gt; &lt;p&gt;So, for anyone else out there with this issue, here's a string for the search engines to chow down on to help any wayward travelers like myself get to the answer they need (at least for now!): &lt;em&gt;InfoPath Forms Services File Attachment The selected file was not found&lt;/em&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31397272-4827792007437276752?l=random-thunks.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://random-thunks.com/feeds/4827792007437276752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://random-thunks.com/2007/06/what-you-mean-found.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/4827792007437276752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31397272/posts/default/4827792007437276752'/><link rel='alternate' type='text/html' href='http://random-thunks.com/2007/06/what-you-mean-found.html' title='What you mean &amp;#39;not found&amp;#39;?'/><author><name>Tiggr</name><uri>http://www.blogger.com/profile/05377102885354870164</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='00864589885050422231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></entry></feed>