<?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:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4059187498168781236</id><updated>2024-11-05T18:44:11.891-08:00</updated><category term="Sql"/><category term=".NET 3.5"/><category term="ADO.NET Entity Framework"/><category term="C#"/><category term="Linq"/><category term="SMO"/><category term="Sql Server"/><category term="SqlSMO"/><category term="Unit Testing"/><title type='text'>Programmed Nirvana</title><subtitle type='html'>Coding help for the lost and those with a desperate need to know.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-1977835918247103009</id><published>2011-12-05T19:05:00.001-08:00</published><updated>2011-12-06T11:39:49.663-08:00</updated><title type='text'>BCP, tab-delimited hell and a good text editor</title><content type='html'>If you&#39;ve ever had a need of quickly loading lots of data into Microsoft Sql Server, then you&#39;ll probably want to use BCP.exe.&lt;br /&gt;
&lt;br /&gt;
BCP is a command line tool for exporting and importing data from tab-delimited files, and believe me when I say it&#39;s fast, it&#39;s FAST. &amp;nbsp;When you are trying to insert hundreds of thousands of records into a table in Sql Server, normal inserts can take hours. &amp;nbsp;With BCP, we&#39;re talking mere seconds.&lt;br /&gt;
&lt;br /&gt;
There is a drawback, however. &amp;nbsp;The tool is not without it&#39;s flaws. &amp;nbsp;The BCP export command will spit out a query to a tab-delimited file, which you can then use to import that data at a later time. &amp;nbsp;But there are times that BCP doesn&#39;t quite do its job right. &amp;nbsp;You&#39;ll find what I refer to as &quot;tab-drift&quot;, where BCP will insert incorrect numbers of tabs, particularly when your data has nulls or empties in some of the columns. &amp;nbsp;What ends up happening is when you import your data, certain rows end up with the columns shifted along, so what was supposed to be in column A ends up in column B, and so on.&lt;br /&gt;
&lt;br /&gt;
Sometimes BCP can correct this if you re-run the BCP command on the original table to re-export the data. &amp;nbsp;Other times, no such luck. &amp;nbsp;In this case, you&#39;ll probably need to correct a couple rows by hand. &amp;nbsp;First you need to find the offending rows (please don&#39;t let there be too many!), then you have to fix them in the bcp export file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And how hard is this? &amp;nbsp;Have you ever opened a tab-delimited file before? &amp;nbsp;If not, there&#39;s not much to look at. &amp;nbsp;A lot of text, a lot of space. &amp;nbsp;Nothing else. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Here we go in notepad...&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj01FtTBzdDES-6KYVNPq1YT2HjLn2HXbK35Gmp3zku7aLc7AkfJ_c_Q6XeK2HiRSrilsoXtA3qWp0IKr8_tcr4l-c297JwswkrALnSiII3e18owp_6InJg_bMZhOUjgNqQwCDLTlON7jk/s1600/notepad.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj01FtTBzdDES-6KYVNPq1YT2HjLn2HXbK35Gmp3zku7aLc7AkfJ_c_Q6XeK2HiRSrilsoXtA3qWp0IKr8_tcr4l-c297JwswkrALnSiII3e18owp_6InJg_bMZhOUjgNqQwCDLTlON7jk/s1600/notepad.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj01FtTBzdDES-6KYVNPq1YT2HjLn2HXbK35Gmp3zku7aLc7AkfJ_c_Q6XeK2HiRSrilsoXtA3qWp0IKr8_tcr4l-c297JwswkrALnSiII3e18owp_6InJg_bMZhOUjgNqQwCDLTlON7jk/s1600/notepad.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;In Visual Studio...&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp-wd9BvRmzSuGS-ZNebGlnWjCuV9sGD96f-NYMKtJSjl0O-GvSaG9LVkVhfyp2lgmLv1H8FLs6SjVD0sLHf7H3JavjuN2jfpmfPWwJNnDclFfAY-9RqlUsothUTDoATeT7SnJxQTuzqE/s1600/visualstudio_simple.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp-wd9BvRmzSuGS-ZNebGlnWjCuV9sGD96f-NYMKtJSjl0O-GvSaG9LVkVhfyp2lgmLv1H8FLs6SjVD0sLHf7H3JavjuN2jfpmfPWwJNnDclFfAY-9RqlUsothUTDoATeT7SnJxQTuzqE/s1600/visualstudio_simple.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You need to be able to see the tabs. &amp;nbsp;You can do this quite easily by using a good text editor, like &lt;a href=&quot;http://www.scintilla.org/SciTE.html&quot;&gt;Scite&lt;/a&gt;, or if you have Visual Studio, use the following command&lt;b&gt; &amp;nbsp;ctrl+E, S&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
What you&#39;ll get now is much more usable...&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieESyVchfY8eDOYukhR0Rfj6Kfx3QaChFzzsfWglYCqPrId8kKjLdJl3IRp9bRSgk5KnrWRQvKI_FSl-zgxeBbvkKQ9aWdVleIXqO-Y8JLcayjHoWCnqmAe0Dc_QiS8heNvx4Ti3zl7YE/s1600/visualstudio_tabshowing.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieESyVchfY8eDOYukhR0Rfj6Kfx3QaChFzzsfWglYCqPrId8kKjLdJl3IRp9bRSgk5KnrWRQvKI_FSl-zgxeBbvkKQ9aWdVleIXqO-Y8JLcayjHoWCnqmAe0Dc_QiS8heNvx4Ti3zl7YE/s1600/visualstudio_tabshowing.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieESyVchfY8eDOYukhR0Rfj6Kfx3QaChFzzsfWglYCqPrId8kKjLdJl3IRp9bRSgk5KnrWRQvKI_FSl-zgxeBbvkKQ9aWdVleIXqO-Y8JLcayjHoWCnqmAe0Dc_QiS8heNvx4Ti3zl7YE/s1600/visualstudio_tabshowing.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of those little blue arrows are tabs. &amp;nbsp;Tabs indicate the separator between columns. &amp;nbsp;If you need to drop in null / blank columns, just drop in additional tabs as needed and you should be all fixed up.&lt;br /&gt;
&lt;br /&gt;
To turn off viewing tabs, just hit the same&amp;nbsp;&lt;b&gt;&amp;nbsp;ctrl+E, S &lt;/b&gt;key again.&lt;br /&gt;
&lt;br /&gt;
Hope this helps. &amp;nbsp;It definitely saved me.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/1977835918247103009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2011/12/bcp-tab-delimited-hell-and-good-text.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/1977835918247103009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/1977835918247103009'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2011/12/bcp-tab-delimited-hell-and-good-text.html' title='BCP, tab-delimited hell and a good text editor'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj01FtTBzdDES-6KYVNPq1YT2HjLn2HXbK35Gmp3zku7aLc7AkfJ_c_Q6XeK2HiRSrilsoXtA3qWp0IKr8_tcr4l-c297JwswkrALnSiII3e18owp_6InJg_bMZhOUjgNqQwCDLTlON7jk/s72-c/notepad.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-2038804737369990232</id><published>2010-12-15T19:22:00.000-08:00</published><updated>2010-12-15T19:22:58.729-08:00</updated><title type='text'>LoadError: no such file to load -- watir</title><content type='html'>For you web developers who need to write good, coded regression tests, Watir is an excellent choice.&amp;nbsp;&lt;div&gt;As quoted from the &lt;a href=&quot;http://watir.com/&quot;&gt;Watir &lt;/a&gt;website:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;color: #333333; font-family: Georgia, &#39;Times New Roman&#39;, Times, serif; font-size: 1em; line-height: 22px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffe599;&quot;&gt;Watir,&amp;nbsp;&lt;a href=&quot;http://dictionary.reference.com/browse/water&quot; style=&quot;color: #3399ff; font-weight: bold; text-decoration: none;&quot;&gt;pronounced&amp;nbsp;&lt;em&gt;&lt;strong&gt;&lt;span style=&quot;color: #3366ff;&quot;&gt;water&lt;/span&gt;&lt;/strong&gt;,&lt;/em&gt;&lt;/a&gt;&amp;nbsp;is an open-source (BSD) family of Ruby libraries for automating web browsers. It allows you to write tests that are&amp;nbsp;easy to read and maintain. It is simple and flexible.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Georgia, &#39;Times New Roman&#39;, Times, serif; font-size: 1em; line-height: 22px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffe599;&quot;&gt;Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;An awesome tool, no doubt about it. &amp;nbsp;It saves us heaps of time on regression testing (our tester is a little inexperienced), load testing, and trying out new stuff and making sure all is running well. &amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;However,&amp;nbsp;you might encounter a problem when trying to run up their &lt;a href=&quot;http://wiki.openqa.org/display/WTR/Watir+in+5+Minutes&quot;&gt;Quick Start Tutorial&lt;/a&gt;&amp;nbsp;or their examples. &amp;nbsp;When you attempt to run anything from the irb or from a ruby script with the following statement:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;i&gt;&lt;b&gt;require &quot;watir&quot;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;You get the following error back:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;i&gt;&lt;b&gt;LoadError: no such file to load -- watir&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;C:\&amp;gt;irb&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #351c75; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;irb(main):001:0&amp;gt; require &#39;watir&#39;
LoadError: no such file to load -- watir
from (irb):1:in `require&#39;
from (irb):1
irb(main):002:0&amp;gt; exit&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #505050;&quot;&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;color: #505050; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; font-weight: normal; white-space: normal;&quot;&gt;You&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; font-weight: normal; white-space: normal;&quot;&gt;&amp;nbsp;can now make sure watir is installed and the version of ruby with the following commands:&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #505050;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;C:\&amp;gt;gem list --local watir
*** LOCAL GEMS ***
watir (1.6.7)

C:\&amp;gt;ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #505050;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div style=&quot;margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;color: #505050; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; font-weight: normal; white-space: normal;&quot;&gt;The fix is simple. &amp;nbsp;You need to load rubygems first.&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;color: #505050; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;color: #505050; display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px; font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;color: #505050; display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; font-weight: normal; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px; font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;C:\&amp;gt;irb
irb(main):001:0&amp;gt; require &#39;watir&#39;
LoadError: no such file to load -- watir
from (irb):1:in `require&#39;
from (irb):1
irb(main):002:0&amp;gt; require &#39;rubygems&#39;
=3D&amp;gt; true
irb(main):003:0&amp;gt; require &#39;watir&#39;
=3D&amp;gt; true&amp;nbsp;&lt;/pre&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px; font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;irb(main):004:0&amp;gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #20124d;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 13px; font-style: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;display: inline !important; font-family: &#39;Segoe UI&#39;, Tahoma, Verdana, Arial, Helvetica; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: pre-wrap; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; width: 760px; word-wrap: break-word;&quot;&gt;&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; white-space: normal;&quot;&gt;&lt;pre class=&quot;FreeTextNG&quot; style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; width: 760px; word-wrap: break-word;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;If this helps you, you owe me a beer.&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/2038804737369990232/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/12/loaderror-no-such-file-to-load-watir.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/2038804737369990232'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/2038804737369990232'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/12/loaderror-no-such-file-to-load-watir.html' title='LoadError: no such file to load -- watir'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-4929133997502502854</id><published>2010-09-21T15:39:00.000-07:00</published><updated>2010-09-21T15:39:41.456-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Unit Testing"/><title type='text'>Transact Sql Unit Testing</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Unit testing is awesome. &amp;nbsp;It has become my new software development passion. &amp;nbsp;Where once&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;I tried to live without it, now I try to dream up tests I haven&#39;t thought of, just so I can write more tests (geeky, I know). &amp;nbsp;All of our C# libraries are unit tested, down to a very, very fine detail, and it is incredible how much cleaner our application is before each release.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Which led me to the idea: &amp;nbsp;why can&#39;t I unit test my sql scripts as well? &amp;nbsp;Seems a logical extension, right? &amp;nbsp;I write a lot of sql procs / scripts for updating data. &amp;nbsp;Why shouldn&#39;t I unit test these changes as well?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;So I looked around, and while I found a few frameworks, and a lot of advice, I didn&#39;t find anything that would work particularly well in our space. &amp;nbsp;The thing was, the frameworks were all written in different languages, like Java or Python. &amp;nbsp;The advice was mostly around commonsense things to do, like after running an update, run another query to ensure the data was there.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;What I wanted was a simple, lightweight set of unit testing tools to help me as I coded my SQL. &amp;nbsp;These would be called to verify my changes either immediately after I updated the data, or in a separate set of scripts. &amp;nbsp;Just like unit tests, right?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;So what I came up with was a simple set of Assert stored procedures.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_IsTrue&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_IsFalse&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_AreEqual&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_AreNotEqual&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_Fail&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_IsNull&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Assert_IsNotNull&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Each of these, like their java / C# / ruby counterparts, allow me to check a given bit of change, and report back if it failed.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;As an example, let me show you a simple call to Assert_IsTrue:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;code&gt;&lt;br /&gt;
declare&lt;br /&gt;
@Result int&lt;br /&gt;
,@ErrorMessage nvarchar(1000)&lt;br /&gt;
&lt;br /&gt;
select @Result = COUNT(1) from etBillingTaxRate where TaxRateAmount = 153.0&lt;br /&gt;
&lt;br /&gt;
set @ErrorMessage = &#39;Could not find a billing tax rate of 153.00&#39;&lt;br /&gt;
&lt;br /&gt;
exec dbo.Assert_IsTrue @Result, @ErrorMessage&lt;br /&gt;
&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;As you can see, the Assert_IsTrue takes 2 parameters: an integer and an nvarchar. &amp;nbsp;The nvarchar is obviously the message to return if the assert fails. &amp;nbsp;For &amp;nbsp;Assert_IsTrue and Assert_IsFalse, I used an integer (as Transact SQL has no boolean data type). &amp;nbsp;If this integer is 1 or greater, the tests passes. &amp;nbsp;If the integer is 0 or less, we get the following when we run the script:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;Msg 50000, Level 15, State 1, Procedure Assert_IsTrue, Line 19&lt;br /&gt;
Could not find a find a billing tax rate of 153.00&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;You can download my assert stored procs from here &lt;a href=&quot;https://docs.google.com/uc?id=0B1xWpcURka_UYTQwZjA5YjItYzljMi00ZjY5LThjZWQtZjY0MGNjNDQwYjhj&amp;amp;export=download&amp;amp;authkey=CPO4wfsM&amp;amp;hl=en&quot;&gt;TSQL_UnitTestingProcs.sql&lt;/a&gt;, and use them in your own Transact SQL projects. &amp;nbsp;For developers of other databases, it would be very easy to port these to your language. &amp;nbsp;They are ridiculously simple, but make your sql coding life so, so much easier.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/4929133997502502854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/09/transact-sql-unit-testing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/4929133997502502854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/4929133997502502854'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/09/transact-sql-unit-testing.html' title='Transact Sql Unit Testing'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-8459390955049588771</id><published>2010-07-06T21:08:00.000-07:00</published><updated>2010-07-06T21:08:08.727-07:00</updated><title type='text'>Try Catch and TransactSQL, oh my</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;One of the great features to TransactSQL since Sql Server 2005 is the Try Catch block.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;For the SQL developer who isn&#39;t also a programmer (are there any of you left out there?), the try catch block is a very useful concept from programming which can serve you very well in your sql scripts.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;Take the following scenario&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin a transaction&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;do something and check if it went down okay&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;do something else and check if it went down okay&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;do something else and check if it went down okay&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;the last one didn&#39;t?! &amp;nbsp;Something went wrong&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;Rollback!&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;Commit&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;This works, but it lacks:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;1. Ease of reading. &amp;nbsp;If I&#39;m a sql developer I can make sense of this, but it isn&#39;t necessarily clear to anyone else. &amp;nbsp;Why is that commit hanging around at the end? &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;2. A mechanism for grouping all your steps together when things go wrong. &amp;nbsp;What if you want to do something else (aka log the attempt) after you rollback? &amp;nbsp;Yes, you can use an IF statement, but again, your code becomes more unreadable.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;Enter the Try Catch. &amp;nbsp;Let&#39;s take the same statement&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin a transaction&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin a try&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; do something&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; do something&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; do something&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Commit&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end try&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin catch&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; Rollback&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end catch&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;Much easier to read. &amp;nbsp;Much cleaner to use.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;Let&#39;s look at a real world example&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from SomeTable where Id = 24&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from SomeOtherTable where Id = 22&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; --this will fail as the table above has a foreign key constraint on this table&#39;s records&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; --and thus must be deleted first&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from FinalTable where Id=26&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; commit transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin catch&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; rollback transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end catch&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;This was good, but we can do better. &amp;nbsp;My queries are protected, but I&#39;m still no wiser as to what the problem was in the first place. &amp;nbsp;Nothing could be simpler. &amp;nbsp;Inside the catch, we have access to the error which threw the exception in the first place. &amp;nbsp;You can do what &amp;nbsp;you like with it, even re-throw it. &amp;nbsp;TransactSQL provides 3 functions to get at our error message and details:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;ERROR_MESSAGE() &amp;nbsp;- This returns the error message&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;ERROR_SEVERITY() - This returns the severity, if you want it&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;ERROR_STATE() - This returns the error state, though I&#39;ve never needed it to date.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;declare&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;@ErrorMessage NVARCHAR(4000)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;,@ErrorSeverity INT&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;,@ErrorState INT&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from SomeTable where Id = 24&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from SomeOtherTable where Id = 22&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; --this will fail as the table above has a foreign key constraint on this table&#39;s records&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; --and thus must be deleted first&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; delete from FinalTable where Id=26&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; commit transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;begin catch&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; rollback transaction&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;div&gt;SELECT&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;@ErrorMessage = ERROR_MESSAGE(),&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;@ErrorSeverity = ERROR_SEVERITY(),&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;@ErrorState = ERROR_STATE();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;--At this point you can do what you like with the error. &amp;nbsp;I&#39;m just rethrowing it after my rollback&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;RAISERROR (@ErrorMessage, -- Message text.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;@ErrorSeverity, -- Severity.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;@ErrorState -- State.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;end catch&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;So what I now get back is the following:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;div&gt;&lt;b&gt;(1 row(s) affected)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;(1 row(s) affected)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;Msg 50000, Level 16, State 0, Line 28&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;The DELETE statement conflicted with the REFERENCE constraint &quot;FK_SomeOtherTable_FinalTable&quot;. The conflict occurred in database &quot;ChrisDB&quot;, table &quot;dbo.SomeOtherTable&quot;, column &#39;FinalTableId&#39;.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;And a query of my tables shows no rows were deleted due to the rollback.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Hope this helps someone out there.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/8459390955049588771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/07/try-catch-and-transactsql-oh-my.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/8459390955049588771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/8459390955049588771'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/07/try-catch-and-transactsql-oh-my.html' title='Try Catch and TransactSQL, oh my'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-5986484601652151988</id><published>2010-06-14T18:55:00.000-07:00</published><updated>2010-06-14T18:55:37.398-07:00</updated><title type='text'>Windows 2008 and COM dlls</title><content type='html'>This was hell.&lt;br /&gt;
&lt;br /&gt;
I have a pretty standard DLL, TidyCOM.dll, which I use in my applications to well, you know what HTML Tidy does. &amp;nbsp;If not, go look it up.&lt;br /&gt;
&lt;br /&gt;
So, I figure it&#39;s as simple as usual: &amp;nbsp;copy the TidyCOM.dll to the system32 directory and run regsvr32.exe against it, as in&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmtEr0A8fdTZx_mfbAdP_5kYNdgTo0QkjCwMFjry48q3GqoSjaqpQWOVKmL3rqxkLNeNHKGdyGKINIszT9flP7n6lU4u23BD9EtGbo4fy37C0cLvOCwTZd6oWFAzXiCwdiNv02xW6oopM/s1600/regsvr32.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmtEr0A8fdTZx_mfbAdP_5kYNdgTo0QkjCwMFjry48q3GqoSjaqpQWOVKmL3rqxkLNeNHKGdyGKINIszT9flP7n6lU4u23BD9EtGbo4fy37C0cLvOCwTZd6oWFAzXiCwdiNv02xW6oopM/s320/regsvr32.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&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;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nope. &amp;nbsp;Fail. &amp;nbsp;There is an error message but I won&#39;t bother you with it. &amp;nbsp;No luck in the universe would make this thing install.&lt;br /&gt;
&lt;br /&gt;
This led to a lot of time spent searching the internet for an answer. &amp;nbsp;What I found was this:&lt;br /&gt;
&lt;br /&gt;
If you are running on a 64-bit machine, the programs in system32 AREN&#39;T 32bit, but instead 64 bit (WTF?!). &amp;nbsp;If you want to register this dll, copy your DLL to the Sys64WOW folder, open a command prompt as an administrator (right click on command prompt and choose &quot;Run as Administrator&quot;), navigate to the windows\Sys64WOW folder and try the above command (regsvr32.exe DLLName.dll) and VOILA! &amp;nbsp;All registered.&lt;br /&gt;
&lt;br /&gt;
And yes, you owe me a coke.</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/5986484601652151988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/06/windows-2008-and-com-dlls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/5986484601652151988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/5986484601652151988'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/06/windows-2008-and-com-dlls.html' title='Windows 2008 and COM dlls'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmtEr0A8fdTZx_mfbAdP_5kYNdgTo0QkjCwMFjry48q3GqoSjaqpQWOVKmL3rqxkLNeNHKGdyGKINIszT9flP7n6lU4u23BD9EtGbo4fy37C0cLvOCwTZd6oWFAzXiCwdiNv02xW6oopM/s72-c/regsvr32.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-8848423090245677651</id><published>2010-05-26T19:12:00.000-07:00</published><updated>2010-05-26T19:27:09.546-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5"/><category scheme="http://www.blogger.com/atom/ns#" term="ADO.NET Entity Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Linq"/><title type='text'>ADO.Net Entity Framework Connection String:  &quot;Keyword not supported: &#39;Data Source&#39;&quot;</title><content type='html'>So you&#39;re new to ADO.Net Entity Framework, and you build a lovely little app, and you use your old connection string from a pre-linq application or website. &amp;nbsp;You put your connection string in the app.config / web.config, which most likely looks something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #073763;&quot;&gt;data source=ServerName;Initial Catalog=SomeDatabase;User Id=sa;Password=pwd&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You reference this connection string in your code like this:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;using (var ents = new LinqADOEntities(Settings.Default.ConnectionString)) &amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And yet when you fire it up, .NET freaks out!&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFYrKDH4NWoW5sG9cHgdz_MjJLK_kVMOVFST0_rlFKTD8vOpkV1Vb172gaTm52PupYqcJciWYrVp6muhAgwuacY1a6Fb7AD6bSk0Bjo6dLi8jY3o5GpLHfSh3lR-vZ0tTrQJErxFGG1hY/s1600/exception_datasource.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFYrKDH4NWoW5sG9cHgdz_MjJLK_kVMOVFST0_rlFKTD8vOpkV1Vb172gaTm52PupYqcJciWYrVp6muhAgwuacY1a6Fb7AD6bSk0Bjo6dLi8jY3o5GpLHfSh3lR-vZ0tTrQJErxFGG1hY/s400/exception_datasource.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well that&#39;s no good. &amp;nbsp;There are countless posts / forums / blogs on the web around this, most of which are confusing, wrong or otherwise leading you down the primrose path. &lt;br /&gt;
&lt;br /&gt;
Here&#39;s the real skinny:&lt;br /&gt;
&lt;br /&gt;
If you&#39;re using ADO.Net Entity Framework, it generates its OWN connection string directly into your app.config / web.config, and it looks NOTHING like an old connection string.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&amp;lt;connectionStrings&amp;gt;&lt;br /&gt;
&amp;lt;add name=&quot;STS_Content_TFSEntities&quot; connectionString=&quot;metadata=res://*/TFS2005_Documents.csdl|res://*/TFS2005_Documents.ssdl|res://*/TFS2005_Documents.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=someServer;Initial Catalog=SomeDB;User Id=sa;Password=pwd;MultipleActiveResultSets=True&quot;&quot; providerName=&quot;System.Data.EntityClient&quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/connectionStrings&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WTF?! &amp;nbsp;Yeah. &amp;nbsp;So if you want to store this in another place, then copy the whole wacky thing over to the other place, wierd metadata= stuff and all. &amp;nbsp;Otherwise, you&#39;ll need to change the values in the app.config / web.config to match your database configuration and call your ADO Entity with an empty constructor. &amp;nbsp;It will find the default connection string as defined in the App.config / web.config. &amp;nbsp;As in...&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;using (var ents = new LinqADOEntities()) &amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;If I&#39;ve saved anyone the 1.25 hours it cost me, I&#39;ll consider it worth my while.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/8848423090245677651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/05/so-youre-new-to-ado.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/8848423090245677651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/8848423090245677651'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/05/so-youre-new-to-ado.html' title='ADO.Net Entity Framework Connection String:  &quot;Keyword not supported: &#39;Data Source&#39;&quot;'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFYrKDH4NWoW5sG9cHgdz_MjJLK_kVMOVFST0_rlFKTD8vOpkV1Vb172gaTm52PupYqcJciWYrVp6muhAgwuacY1a6Fb7AD6bSk0Bjo6dLi8jY3o5GpLHfSh3lR-vZ0tTrQJErxFGG1hY/s72-c/exception_datasource.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-6413574015937784669</id><published>2010-05-17T21:06:00.000-07:00</published><updated>2010-05-17T21:06:08.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Sql Chat:  Avoid the &#39;OR&#39;</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Sql. &amp;nbsp;Structured Query Language. &amp;nbsp;The joy and bane of so many developers&#39; lives. &amp;nbsp;It can make or break you in the development game, and have you up at three in the morning saying &quot;but WHY am I getting duplicates?!&quot;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I have friends who try very hard to avoid using it. &amp;nbsp;They are the products of modern programming. &amp;nbsp;Data Entities that automatically update your data when you call a save method. &amp;nbsp;Code layers that remove the complexity of data from the developer. &amp;nbsp;Blah. &amp;nbsp;Blah. &amp;nbsp;Blah.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
This is really nice-sounding and lots of guys I know swear they don&#39;t need to know&amp;nbsp;Sql. &amp;nbsp;Then their boss wants a report, tabulated and summed and pivoted by all kinds of crazy things. &amp;nbsp;Entity objects suddenly become Satan&#39;s little minions. &amp;nbsp;If the only tool you have is a hammer, soldering that tiny wire back into place is gonna be one nasty job.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If you&#39;re using a database in your application, and you don&#39;t know&amp;nbsp;Sql, here&#39;s some free advice: &amp;nbsp;Man up, get a book (or look online) and learn it. &amp;nbsp;You&#39;ll never regret it. &amp;nbsp;It always is a bonus knowing at least a little&amp;nbsp;Sql. &amp;nbsp;It impresses database admins, and who doesn&#39;t want to impress them, right? &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Plus you can lord it over your other geek friends who DON&#39;T know it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Over the coming weeks and months, I&#39;ll be writing a regular blog on Sql. &amp;nbsp;This will NOT be an introduction to&amp;nbsp;Sql. &amp;nbsp;If you want an intro to&amp;nbsp;Sql, here you go:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.w3schools.com/sql/sql_intro.asp&quot;&gt;http://www.w3schools.com/sql/sql_intro.asp&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;What I&#39;ll be focusing on is some of those tricks and traps in&amp;nbsp;Sql&amp;nbsp;which will set you apart from the average&amp;nbsp;Sql&amp;nbsp;nerd. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;************************************************************************************************************&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;With that said, let&#39;s get stuck in. &amp;nbsp;Today, we&#39;ll be talking about the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;OR statement, and why you should avoid this like the damned plague.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;At first glance, an OR statement would seem like a reasonably good idea.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;b&gt;select * from ObjectTable where ObjectId = 1234 or ObjectId = 2345&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Get one OR the other, right? &amp;nbsp;Sure. &amp;nbsp;Good idea in simple scenarios such as this one, and fine if you are dealing with primary keys. &amp;nbsp;Nice and clean. &amp;nbsp;However, let&#39;s go a little further with this example:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;select * from ObjectTable where ObjectTypeCode = &#39;Code1&#39; or&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;ObjectTypeCode = &#39;Code2&#39;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Now we aren&#39;t talking about a primary key any more. &amp;nbsp;We&#39;re talking about a string hanging off the side which is a property. &amp;nbsp;Now the database is scanning to find which records have ObjectTypeCode of &#39;Code1&#39; OR have &#39;Code2&#39;. &amp;nbsp;This is a lot of scanning. &amp;nbsp;Your db server is saying:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&quot;This one? &amp;nbsp;No. &amp;nbsp;This one? &amp;nbsp;Yes. &amp;nbsp;This one? &amp;nbsp;No. &amp;nbsp;This one? &amp;nbsp;Yes&quot;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This is time consuming, and at all costs we wish to consume less time on the db. &amp;nbsp;Less time means less CPU being used, and less CPU means...well less CPU. &amp;nbsp;Yes, indexing can (and will help), but indexing for indexing sake can actually end up biting you in the ass. &amp;nbsp;Too many indexes is worse than too few, as the system wastes ridiculous amounts of time updating all these indexes that are only there to help you out in those rare scenarios where you want to pull off an OR statement.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;And for all you smart-asses out there, don&#39;t think this trick will help you either:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;select * from ObjectTable where ObjectTypeCode in (&#39;Code1&#39;,&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;&#39;Code2&#39;)&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This is basically the same thing, just in prettier shorthand. &amp;nbsp;Trust me. &amp;nbsp;I tried it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;So how do we avoid this nasty OR statement (if we can help it)? &amp;nbsp;Obviously, there are times we NEED an OR statement.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; What are our alternatives.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Remember that SQL is a set-based language. &amp;nbsp;When you make a query in Sql, we are &amp;nbsp;trying to group together things that meet the criteria in your joins and where clause. &amp;nbsp;The tighter this joining is, the less time your &amp;nbsp;database server will use trying to find it. &amp;nbsp;So here are some good rules:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;1. If you query for these values OFTEN, maybe you need to rethink your data structure. &amp;nbsp;Rather than this:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJvwnUlqh-6s5TFHDyx6RAqrt3NrLnFn0WaxT0XVKp7Bew4VowMsbskg29msjX3f4onoW0TMBM9_xb_u3xjf5Kf2RoifHP9Zv3pUpk4pSxd_B0H3ce7tStohnApB10nrDU5Fmd4l3YQCA/s1600/ObjectTable.GIF&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJvwnUlqh-6s5TFHDyx6RAqrt3NrLnFn0WaxT0XVKp7Bew4VowMsbskg29msjX3f4onoW0TMBM9_xb_u3xjf5Kf2RoifHP9Zv3pUpk4pSxd_B0H3ce7tStohnApB10nrDU5Fmd4l3YQCA/s320/ObjectTable.GIF&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;You might consider this: &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKkPoJOAs5p2bjsDsdrxjjveRWQCN265p9KI1dPYyjA7JcO0k81pfMJXNX3Q8NODDGpFcThHLjGNletSHwMaEQCV4NUMe0XcSsZe0x3811EkUf8meMFd4MYKELZ1jARtZasvyz4FY9K4A/s1600/ObjectTable_Refactor.GIF&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;182&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKkPoJOAs5p2bjsDsdrxjjveRWQCN265p9KI1dPYyjA7JcO0k81pfMJXNX3Q8NODDGpFcThHLjGNletSHwMaEQCV4NUMe0XcSsZe0x3811EkUf8meMFd4MYKELZ1jARtZasvyz4FY9K4A/s400/ObjectTable_Refactor.GIF&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Note the column &#39;GroupingCode&#39;. &amp;nbsp;You can group your ObjectTypeCode values using the GroupingCode as in:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;col style=&quot;mso-width-alt: 6582; mso-width-source: userset; width: 135pt;&quot; width=&quot;180&quot;&gt;&lt;/col&gt;  &lt;col style=&quot;mso-width-alt: 7314; mso-width-source: userset; width: 150pt;&quot; width=&quot;200&quot;&gt;&lt;/col&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td class=&quot;xl63&quot; height=&quot;20&quot; style=&quot;height: 15.0pt; width: 135pt;&quot; width=&quot;180&quot;&gt;&lt;b&gt;ObjectTypeCode&lt;/b&gt;&lt;/td&gt;   &lt;td class=&quot;xl63&quot; style=&quot;width: 150pt;&quot; width=&quot;200&quot;&gt;&lt;b&gt;GroupingCode&lt;/b&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Code1&lt;/span&gt;&lt;/td&gt;   &lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Group1&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Code2&lt;/span&gt;&lt;/td&gt;   &lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Group1&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;Code3&lt;/td&gt;   &lt;td&gt;Group2&lt;/td&gt;  &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;Code4&lt;/td&gt;   &lt;td&gt;Group2&lt;/td&gt;  &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;   &lt;td height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Code5&lt;/span&gt;&lt;/td&gt;   &lt;td&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: lime;&quot;&gt;Group1&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Now you have a usable set which can grab records quickly. &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;select&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;* from ObjectTable ecot&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;join ecObjectType ecott on ecot.ObjectTypeId = ecott.ObjectTypeId&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;&amp;nbsp;where ecott.GroupingCode = &#39;Group1&#39;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This is going to be far faster, because we are joining on a single key, not multiples that require 2x the table searching.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;2. If you can, try the reverse. &amp;nbsp;For example, if you have 3 values in ObjectType, our two above and another one called &#39;Bleck&#39;, try this instead:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;b&gt;select * from ObjectTable where ObjectTypeCode &amp;lt;&amp;gt; &#39;Bleck&#39;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;3. Like this?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;select * from ObjectTable where ObjectTypeCode like &#39;Counter%&#39;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;This doesn&#39;t work in all flavors of Sql, but in transact-sql it can be lightning fast, particularly if you full-text index the column.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
That&#39;s it! &amp;nbsp;Hope it helps. &amp;nbsp;Remember, dodge that OR. &amp;nbsp;There is usually a solution around it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/6413574015937784669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/05/sql-chat-avoid-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/6413574015937784669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/6413574015937784669'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/05/sql-chat-avoid-or.html' title='Sql Chat:  Avoid the &#39;OR&#39;'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJvwnUlqh-6s5TFHDyx6RAqrt3NrLnFn0WaxT0XVKp7Bew4VowMsbskg29msjX3f4onoW0TMBM9_xb_u3xjf5Kf2RoifHP9Zv3pUpk4pSxd_B0H3ce7tStohnApB10nrDU5Fmd4l3YQCA/s72-c/ObjectTable.GIF" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4059187498168781236.post-7247674337717059051</id><published>2010-02-11T17:23:00.000-08:00</published><updated>2010-02-11T17:28:36.585-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SMO"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SqlSMO"/><title type='text'>Create a Stored Procedure with SQL SMO</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I am currently rewriting an existing data generator which was written in Sql dmo, but now must be in Sql Smo.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Creating a stored procedure is a pretty straightforward affair. Add your header references:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; line-height: 17px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;Microsoft.SqlServer.Management.Smo;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;Microsoft.SqlServer.Management.Smo.Agent;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;using&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;Microsoft.SqlServer.Management.Common;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;And here&#39;s the most commonly used code I&#39;ve found online:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;color: teal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;color: teal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;StoredProcedure&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;mySP;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: teal; font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;String &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;procString = &quot;PUT YOUR PROCTEXTHERE&quot;;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: teal; font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;mySP =&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: teal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;StoredProcedure&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;(sqlserver.database,&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&quot;SomeProcName&quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;);&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: teal; font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;mySP.TextBody =&amp;nbsp;procString;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: teal; font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;mySP.Create();&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Something important to note here is that very often you will get back a nasty exception if you&#39;re not careful:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Create failed for StoredProcedure &#39;dbo.SomeProcName&#39;.&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;WTF?! &amp;nbsp;Read the exception more carefully and you&#39;ll find the following explanatory note:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;To accomplish this action, set property ExecutionContext.&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Hmmmm. &amp;nbsp;What the hell is this, then? &amp;nbsp;The problem is the context of who is attempting to create this procedure on your database. &amp;nbsp;Okay, so we attempt to set the execution context to, say the owner, but the moment you try to set the executioncontext on your stored procedure, you will get another exception!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Writing property ExecutionContext of StoredProcedure &#39;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;dbo.SomeProcName&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&#39; is not allowed when TextMode has been set.&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Why is anyone&#39;s guess, but I haven&#39;t found a satisfactory answer anywhere on MSDN or the web. &amp;nbsp;I decided to take a more tai chi approach to this problem and dodged the stored proc object entirely:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;ServerConnection &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;conn = new &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;ServerConnection&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;(&quot;ServerName&quot;, &quot;UserName&quot;, &quot;Password&quot;);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;myServer = new &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Server&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;(conn);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;String &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;procString = &quot;create procedure [dbo].[SomeProcName]() as begin select top 1 from someTable; &amp;nbsp;end&quot;;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Database &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;myDb = myServer.Databases[&quot;DatabaseName&quot;];&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; myDb.ExecuteNonQuery(procString);&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;/div&gt;&lt;div style=&quot;margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 1em;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Here&#39;s hoping this saves you some headache as it did me.&lt;/span&gt; &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmednirvana.blogspot.com/feeds/7247674337717059051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmednirvana.blogspot.com/2010/02/create-stored-procedure-with-sql-smo.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/7247674337717059051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4059187498168781236/posts/default/7247674337717059051'/><link rel='alternate' type='text/html' href='http://programmednirvana.blogspot.com/2010/02/create-stored-procedure-with-sql-smo.html' title='Create a Stored Procedure with SQL SMO'/><author><name>Chris Smith</name><uri>http://www.blogger.com/profile/18201609242208308102</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio7aqnMy-mhmA6kt6N37_RCcu44oIa5g_fs0_f_lrLlIVyfZb-MO9k0WmFXkaThYVJqtQM4S8KB5iyF1f8yI2CC-SyD4AUwnY_nTXh3BHgOiJt56o2A2UkSDC42rh40Q/s220/Cobra.gif'/></author><thr:total>0</thr:total></entry></feed>