<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JohnnyCoder &#187; SQL Server</title>
	<atom:link href="http://johnnycoder.com/blog/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnnycoder.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 03 Nov 2010 17:07:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Database Connectivity Test with UDL File</title>
		<link>http://johnnycoder.com/blog/2010/06/12/database-connectivity-test-with-udl-file/</link>
		<comments>http://johnnycoder.com/blog/2010/06/12/database-connectivity-test-with-udl-file/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 20:54:52 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Tip and Tricks]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/06/12/database-connectivity-test-with-udl-file/</guid>
		<description><![CDATA[I bounced around between projects a lot last week.&#160; What each project had in common was the need to validate at least one SQL connection.&#160; Whether you have SQL tools like SSMS installed or not, this is a very easy task if you are aware of the UDL (Universal Data Link) files.&#160; Create a new [...]]]></description>
			<content:encoded><![CDATA[<p>I bounced around between projects a lot last week.&#160; What each project had in common was the need to validate at least one SQL connection.&#160; Whether you have SQL tools like SSMS installed or not, this is a very easy task if you are aware of the UDL (Universal Data Link) files.&#160; </p>
<p>Create a new file and name it anything as long as it has the .udl extension. Open the file, choose a provider:</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image_thumb.png" width="371" height="464" /></a> </p>
<p>Click Next &gt;&gt; or navigate to the Connection Tab to provide connection information.&#160; Once you provide server and login credentials, the database list will populate.&#160; At this point, you know the connection is valid. but go ahead and click the Test Connection button anyway.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image_thumb1.png" width="371" height="464" /></a> </p>
<p>On the final tab, you can provide extra connection information like <a href="http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/">Application Name which can come in handy</a>.&#160; </p>
</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/06/image_thumb2.png" width="371" height="464" /></a> </p>
<p>The All tab is beneficial if you want to build a valid connection string to include in your own applications.&#160; If you save the file and then open in Notepad, you’ll find that said connection string:</p>
<blockquote><p>Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=(local);Application Name=TestApp</p>
</blockquote>
<p>I hope this tip helps save you some time.&#160; How do you test if you don’t have SSMS installed?</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/06/12/database-connectivity-test-with-udl-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configure SQL Server to Allow Remote Connections</title>
		<link>http://johnnycoder.com/blog/2010/03/24/configure-sql-server-to-allow-remote-connections/</link>
		<comments>http://johnnycoder.com/blog/2010/03/24/configure-sql-server-to-allow-remote-connections/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:44:09 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Services]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/03/24/configure-sql-server-to-allow-remote-connections/</guid>
		<description><![CDATA[Okay. This post isn’t about configuring SQL to allow remote connections, but wait, I still may be able to help you out. &#34;A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>Okay. This post isn’t about configuring SQL to allow remote connections, but wait, I still may be able to help you out.</p>
<p><em>&quot;A network-related or instance-specific error occurred while establishing a connection to SQL Server. The <a href="http://johnnycoder.com/blog/wp-content/uploads/2010/03/image5.png"><img style="border-right-width: 0px; margin: 15px 10px 15px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://johnnycoder.com/blog/wp-content/uploads/2010/03/image_thumb1.png" width="244" height="172" /></a>server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 &#8211; Could not open a connection to SQL Server)&quot;</em></p>
<p>I love this exception. It summarized the issue and leads you down a path to solving the problem.&#160; I do wish the bit about allowing remote connections was left out of the message though. I can’t think of a time when having remote connections disabled caused me grief.&#160; Heck, I can’t ever remember how to enable remote connections unless I Google for the answer.</p>
<p>Anyway, 9 out of 10 times, SQL Server simply isn’t running.&#160; That’s why the exception occurs.&#160; The next time this exception pops up, open up the services console and make sure SQL Server is started.&#160; And if that’s not the problem, only then start digging into the other possible reasons for the failure.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/03/24/configure-sql-server-to-allow-remote-connections/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting Started with ASP.NET Membership, Profile and RoleManager</title>
		<link>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/</link>
		<comments>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 07:26:29 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/</guid>
		<description><![CDATA[A new ASP.NET MVC project includes preconfigured Membership, Profile and RoleManager providers right out of the box.&#160; Try it yourself – create a ASP.NET MVC application, crack open the web.config file and have a look.&#160; First, you’ll find the ApplicationServices database connection: &#60;connectionStrings&#62; &#160;&#160;&#60;add name=&#34;ApplicationServices&#34; &#160;&#160;&#160;&#160;&#160;&#160;&#160;connectionString=&#34;data source=.&#92;SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=&#124;DataDirectory&#124;aspnetdb.mdf;User Instance=true&#34; &#160;&#160;&#160;&#160;&#160;&#160;&#160;providerName=&#34;System.Data.SqlClient&#34;/&#62; &#60;/connectionStrings&#62; &#160; Notice the connection [...]]]></description>
			<content:encoded><![CDATA[<p>A new ASP.NET MVC project includes preconfigured Membership, Profile and RoleManager providers right out of the box.&#160; Try it yourself – create a ASP.NET MVC application, crack open the web.config file and have a look.&#160; </p>
<p>First, you’ll find the ApplicationServices database connection:    </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:417f66b0-c156-4264-b09d-f28075be06ad" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionString</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">data source=.&#92;SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">providerName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Data.SqlClient</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Notice the connection string is referencing the aspnetdb.mdf database hosted by SQL Express and it’s using integrated security so it’ll just work for you without having to call out a specific database login or anything. </p>
<p>Scroll down the file a bit and you’ll find each of the three noted sections:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5dda06dc-c123-40b9-a65b-cb0ff1c317dd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">membership</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlMembershipProvider</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">enablePasswordRetrieval</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">enablePasswordReset</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">true</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">requiresQuestionAndAnswer</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">requiresUniqueEmail</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordFormat</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Hashed</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">maxInvalidPasswordAttempts</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">5</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">minRequiredPasswordLength</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">6</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">minRequiredNonalphanumericCharacters</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">0</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordAttemptWindow</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">10</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordStrengthRegularExpression</span><span style="color:#0000ff">=</span>&quot;&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">membership</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">profile</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlProfileProvider</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">profile</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">roleManager</span><span style="color:#0000ff"> </span><span style="color:#ff0000">enabled</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlRoleProvider</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetWindowsTokenRoleProvider</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">roleManager</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Really. It’s all there. Still don’t believe me.&#160; Run the application, walk through the registration process and finally login and logout.&#160; Completely functional – and you didn’t have to do a thing!</p>
<p>What else?&#160; Well, you can manage your users via the Configuration Manager which is hiding in Visual Studio behind Projects &gt; ASP.NET Configuration.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb.png" width="252" height="342" /></a> </p>
<p>The ASP.NET Web Site Administration Tool isn’t MVC-specific (neither is the Membership, Profile or RoleManager stuff) but it’s neat and I hardly ever see anyone using it.&#160; Here you can set up and edit users, roles, and set access permissions for your site. You can manage application settings, establish your SMTP settings, configure debugging and tracing, define default error page and even take your application offline.&#160; The UI is rather plain-Jane but it works great.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb1.png" width="779" height="452" /></a></p>
<p>And here’s the best of all.&#160; Let’s say you, like most of us, don’t want to run your application on top of the aspnetdb.mdf database.&#160; Let’s suppose you want to use your own database and you’d like to add the membership stuff to it.&#160; Well, that’s easy enough. Take a look inside your [drive:]\%windir%\Microsoft.Net\Framework\v2.0.50727\ folder.&#160; Here you’ll find a bunch of files.&#160; If you were to run the InstallCommon.sql, InstallMembership.sql, InstallRoles.sql and InstallProfile.sql files against the database of your choices, you’d be installing the same membership, profile and role artifacts which are found in the aspnet.db to your own database.&#160; </p>
<p>Too much trouble?&#160; Okay. Run [drive:]\%windir%\Microsoft.Net\Framework\v2.0.50727\aspnet_regsql.exe from the command line instead.&#160; This will launch the ASP.NET SQL Server Setup Wizard which walks you through the installation of those same database objects into the new or existing database of your choice. You may not always have the luxury of using this tool on your destination server, but you should use it whenever you can.&#160; </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb2.png" width="592" height="458" /></a> </p>
<p>Last tip: don’t forget to update the ApplicationServices connectionstring to point to your custom database after the setup is complete.</p>
<p>At the risk of sounding like a smarty, everything I’ve mentioned in this post has been around for quite a while. The thing is that not everyone has had the opportunity to use it.&#160; And it makes sense. I know I’ve worked on projects which used custom membership services.&#160; Why bother with the out-of-the-box stuff, right?&#160;&#160; And the .NET framework is so massive, who can know it all. Well, eventually you might have a chance to architect your own solution using any implementation you’d like or you will have the time to play around with another aspect of the framework.&#160; When you do, think back to this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Issue Creating SQL Login for AppPoolIdentity on Windows Server 2008</title>
		<link>http://johnnycoder.com/blog/2009/12/31/issue-creating-sql-login-for-apppoolidentity-on-windows-server-2008/</link>
		<comments>http://johnnycoder.com/blog/2009/12/31/issue-creating-sql-login-for-apppoolidentity-on-windows-server-2008/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 21:05:03 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[IIS]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/12/31/issue-creating-sql-login-for-apppoolidentity-on-windows-server-2008/</guid>
		<description><![CDATA[IIS7 introduced the option to run your application pool as AppPoolIdentity. With the release of IIS7.5, AppPoolIdentity was promoted to the default option.&#160; You see this change if you’re running Windows 7 or Windows Server 2008 R2.&#160; On my Windows 7 machine, I’m able to define my Application Pool Identity and then create an associated [...]]]></description>
			<content:encoded><![CDATA[<p>IIS7 introduced the option to run your application pool as <a href="http://learn.iis.net/page.aspx/624/application-pool-identities/">AppPoolIdentity</a>. With the release of IIS7.5, AppPoolIdentity was promoted to the default option.&#160; You see this change if you’re running Windows 7 or Windows Server 2008 R2.&#160; <a href="http://johnnycoder.com/blog/wp-content/uploads/2009/12/image7.png"><img style="border-right-width: 0px; margin: 10px 10px 10px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://johnnycoder.com/blog/wp-content/uploads/2009/12/image-thumb7.png" width="240" height="216" /></a></p>
<p>On my Windows 7 machine, I’m able to define my Application Pool Identity and then create an associated database login via the SQL Server Management Studio interface.&#160; No problem.&#160; However, I ran into some troubles when recently installing my web application onto a Windows Server 2008 R2 64-bit machine.&#160; Strange, but the same approach failed as <a href="http://forums.iis.net/p/1162459/1924222.aspx">SSMS couldn’t find the AppPoolIdentity user</a>.&#160; Instead of using the tools, I created and executed the login via script and it worked fine.&#160; </p>
<p>Here’s the script, based off of the DefaultAppPool identity, if the same happens to you:</p>
<blockquote><p>CREATE LOGIN [IIS APPPOOL\DefaultAppPool]      <br />FROM WINDOWS WITH DEFAULT_DATABASE=[master]       <br />USE [Chinook]       <br />CREATE USER [IIS APPPOOL\DefaultAppPool] FOR LOGIN [IIS APPPOOL\DefaultAppPool] </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/12/31/issue-creating-sql-login-for-apppoolidentity-on-windows-server-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Keystrokes to Set Null Value in SSMS</title>
		<link>http://johnnycoder.com/blog/2009/05/13/keystrokes-to-set-null-value-in-ssms/</link>
		<comments>http://johnnycoder.com/blog/2009/05/13/keystrokes-to-set-null-value-in-ssms/#comments</comments>
		<pubDate>Wed, 13 May 2009 22:50:22 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/05/13/keystrokes-to-set-null-value-in-ssms/</guid>
		<description><![CDATA[Let’s say you are viewing results in Enterprise Manager or the SQL Server Management Tools and you really want to update a cell will a NULL value.&#160; Sure you could script it.&#160; Heck, you’re welcome to wrap the one line script in a Transaction and produce a rollback script as well if you’d like.&#160; But, [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s say you are viewing results in Enterprise Manager or the SQL Server Management Tools and you really want to update a cell will a NULL value.&#160; Sure you could script it.&#160; Heck, you’re welcome to wrap the one line script in a Transaction and produce a rollback script as well if you’d like.&#160; But, if you are lazy like me, you just want to update the value using tools, all reckless-like.&#160; The trick is to select into the cell and press the lucky CTRL + 0 key combo. That’s a zero, by the way. I also go for CTRL + DEL, and then wonder why NULL doesn’t magically appear.&#160; Hence the post.&#160; </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2009/05/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2009/05/image-thumb11.png" width="547" height="152" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/05/13/keystrokes-to-set-null-value-in-ssms/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Upgrade to SQL Server 2008 with SQL Server Management Studio (SSMS) 2008</title>
		<link>http://johnnycoder.com/blog/2009/04/04/upgrade-to-sql-server-2008-with-sql-server-management-studio-ssms-2008/</link>
		<comments>http://johnnycoder.com/blog/2009/04/04/upgrade-to-sql-server-2008-with-sql-server-management-studio-ssms-2008/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 23:52:32 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/04/04/upgrade-to-sql-server-2008-with-sql-server-management-studio-ssms-2008/</guid>
		<description><![CDATA[I have installed SQL Server 2008 and SQL Server Management Studio 2008 a number of times and it has always been a snap*..until yesterday. As it turns out, previous installations were always applied to machines (mostly VMs) which weren’t running early versions of the SQL Server and associated tools.&#160; Yesterday, I performed my first upgrade [...]]]></description>
			<content:encoded><![CDATA[<p>I have installed SQL Server 2008 and SQL Server Management Studio 2008 a number of times and it has always been a snap*..until yesterday. </p>
<p>As it turns out, previous installations were always applied to machines (mostly VMs) which weren’t running early versions of the SQL Server and associated tools.&#160; Yesterday, I performed my first upgrade from SQL Server 2008 and SQL Server Management Studio 2005 and it took a painfully long time to get everything in place.</p>
<p>There seems to be general discontent with the SQL Server 2008 installation/upgrade experience – particularly when it comes to SQL Server Management Studio. After yesterday’s debacle, I can understand why.&#160; In retrospect, an upgrade to 2008 is simple if you follow the right steps.&#160; If not, you’re bound to get frustrated and waste a couple of hours.&#160; </p>
<p>If I knew then what I know now…</p>
<ul>
<li>You cannot manage SQL Server 2008 with 2005 Management Tools. Go ahead and try it. SQL Server Management Studio 2005 will bark at you. </li>
<li>A stand-alone SQL Server Management Studio 2008 installer does not exist.&#160; The Management Tools must be installed as a features available via the main SQL Server2008 installer. The Microsoft download for SQL Server Management Studio 2008, as far as I am concern is a hoax.&#160; It is merely the SQL Server 2008 installer given a different file name. Seriously. </li>
<li>You cannot run SQL Server Management Studio 2005 and SQL Server Management Studio 2008 side by side. An attempt to install SSMS 2008 will fail if you have yet to uninstall SSMS 2005. </li>
</ul>
<p>Save yourself some trouble.&#160; Before kicking off your SQL Server 2008 / SQL Server Management Studio 2008 installation or upgrade, uninstall SQL Server Management Studio 2005.&#160; If you <a href="http://johnnycoder.com/blog/wp-content/uploads/2009/04/image5.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 10px 5px 10px 10px; border-right-width: 0px" height="209" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2009/04/image-thumb4.png" width="244" align="right" border="0" /></a>don’t, you will be able to successfully install SQL Server 2008, but the Management Tools installation will fail (gracefully.) If, per chance, you find yourself in this failure condition, continue with the SQL Server Management Studio 2005 uninstall, rerun the SQL Server 2008 installer and reattempt the Management Tools installation.&#160; This can be done by following the “New SQL Server stand-alone installation of add features to an existing installation” option under the Installation view.&#160; This time around select the Management Tools when the available features are presented and you should be all set.&#160; You may find the management tools take a surprisingly long time to install, but, believe me, this is nothing compared to the time you might waste if you didn’t know the right steps to follow in the first place.</p>
<p><em>* Relatively standard installation instructions which work consistently well for me:</em></p>
<ul>
<li><em>Run Setup.exe </em></li>
<li><em>Installation &gt; Select “New SQL Server stand-alone installation or add features to an existing installation.” </em></li>
<li><em>Select the following Features: </em>
<ul>
<li><em>Database Engine Services </em></li>
<li><em>Reporting Services </em></li>
<li><em>Client Tools Connectivity </em></li>
<li><em>Management Tools – Basic (If SSMS 2005 isn’t installed) </em></li>
<li><em>Management Tools – Complete (If SSMS 2005 isn’t installed) </em></li>
</ul>
</li>
<li><em>Select the Named Instance/Instance ID based on established naming convention. For example, BGHOMESQL01 </em></li>
<li><em>Set the following Service Startup Types: </em>
<ul>
<li><em>SQL Server Agent – Automatic </em></li>
<li><em>SQL Server Database Engine – Automatic </em></li>
<li><em>SQL Server Reporting Services – Automatic </em></li>
</ul>
</li>
<li><em>Use the same account for all SQL Server Services and provide account. On local machine, I suggest using the Current User. </em></li>
<li><em>Set the Authentication Mode: </em>
<ul>
<li><em>Mixed Mode (SQL Server Authentication and Windows Authentication) </em></li>
</ul>
</li>
<li><em>Provide the built-in SQL Server admin account. On local machine, I suggest using the Current User. </em></li>
<li><em>Configure Reporting Services: </em>
<ul>
<li><em>Install the native mode default configuration </em></li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/04/04/upgrade-to-sql-server-2008-with-sql-server-management-studio-ssms-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Tip: Uniquely Name Table Columns</title>
		<link>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/</link>
		<comments>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 23:43:58 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/</guid>
		<description><![CDATA[It is easy to see the subtle difference between the Product Tables below.  The table to the left adds the table name as a prefix to nearly all of the column names. The table on the right represents very simple column names with no redundancy.  Early in my career, I preferred the implementation to the [...]]]></description>
			<content:encoded><![CDATA[<p>It is easy to see the subtle difference between the Product Tables below.  The table to the left adds the table name as a prefix to nearly all of the column names. <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image10.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/06/image-thumb6.png" border="0" alt="image" width="475" height="195" align="right" /></a> The table on the right represents very simple column names with no redundancy.  Early in my career, I preferred the implementation to the right as I felt this pattern best represented the object (table) itself.  After all, we all have a<em> name.  </em>We don&#8217;t have a <em>PersonName.</em> Well,<em> </em>it didn&#8217;t take me long to change my opinion.</p>
<p>The next time you are designing a database, do yourself a favor and mimic the pattern to the left.  <strong>Always prefix column names with the table name if the column name is likely to be repeated  in more than one table.</strong>  ID, Name, Description, DateAdd and DateChange are good examples of column names which tend to show up in multiple places.  When it comes time to build your queries and work with the result sets, you will thank me. </p>
<p>Consider the two following routines &#8212; each returns the same result but the latter is much cleaner, readable, consists of less code and is inherently greater resistant to stupid coding errors especially within the syntax of the join and the column aliases.</p>
<pre class="code"><span style="color: #008000;">-- Poor implementation
</span><span style="color: #0000ff;">declare </span>@Product <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span><span style="color: #0000ff;">Name varchar</span><span style="color: #808080;">(</span>50<span style="color: #808080;">)
)

</span><span style="color: #0000ff;">declare </span>@ProductVersion <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>VersionNumber <span style="color: #0000ff;">int
</span><span style="color: #808080;">)

</span><span style="color: #0000ff;">insert into </span>@Product<span style="color: #808080;">(</span>ID<span style="color: #808080;">, </span><span style="color: #0000ff;">Name</span><span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 1'
</span><span style="color: #0000ff;">union
select </span>2<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 2'

</span><span style="color: #0000ff;">insert into </span>@ProductVersion <span style="color: #808080;">(</span>ID<span style="color: #808080;">, </span>ProductID<span style="color: #808080;">, </span>VersionNumber<span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span>1<span style="color: #808080;">, </span>1
<span style="color: #0000ff;">union
select </span>1<span style="color: #808080;">, </span>2<span style="color: #808080;">, </span>1

<span style="color: #008000;">-- Note the column aliases and
-- join on less-than-obvious columns
</span><span style="color: #0000ff;">select </span>P<span style="color: #808080;">.</span>ID <span style="color: #0000ff;">as </span>ProductID<span style="color: #808080;">, </span>PV<span style="color: #808080;">.</span>ID <span style="color: #0000ff;">as </span>ProductVersionID <span style="color: #0000ff;">from
</span>@Product P <span style="color: #808080;">inner join
</span>@ProductVersion PV <span style="color: #0000ff;">on </span><span style="color: #808080;">(</span>P<span style="color: #808080;">.</span>ID <span style="color: #808080;">= </span>PV<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">)

</span>go

<span style="color: #008000;">-- Proper implementation
</span><span style="color: #0000ff;">declare </span>@Product <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span><span style="color: #0000ff;">Name varchar</span><span style="color: #808080;">(</span>50<span style="color: #808080;">)
)

</span><span style="color: #0000ff;">declare </span>@ProductVersion <span style="color: #0000ff;">table
</span><span style="color: #808080;">(
    </span>ProductVersionID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>ProductID <span style="color: #0000ff;">int</span><span style="color: #808080;">, </span>VersionNumber <span style="color: #0000ff;">int
</span><span style="color: #808080;">)

</span><span style="color: #0000ff;">insert into </span>@Product<span style="color: #808080;">(</span>ProductID<span style="color: #808080;">, </span><span style="color: #0000ff;">Name</span><span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 1'
</span><span style="color: #0000ff;">union
select </span>2<span style="color: #808080;">, </span><span style="color: #ff0000;">'product 2'

</span><span style="color: #0000ff;">insert into </span>@ProductVersion <span style="color: #808080;">(</span>ProductVersionID<span style="color: #808080;">, </span>ProductID<span style="color: #808080;">, </span>VersionNumber<span style="color: #808080;">)
</span><span style="color: #0000ff;">select </span>1<span style="color: #808080;">, </span>1<span style="color: #808080;">, </span>1
<span style="color: #0000ff;">union
select </span>1<span style="color: #808080;">, </span>2<span style="color: #808080;">, </span>1

<span style="color: #008000;">-- Note there's no need for aliases and
-- the join obvious
</span><span style="color: #0000ff;">select </span>P<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">, </span>PV<span style="color: #808080;">.</span>ProductVersionID <span style="color: #0000ff;">from
</span>@Product P <span style="color: #808080;">inner join
</span>@ProductVersion PV <span style="color: #0000ff;">on </span><span style="color: #808080;">(</span>P<span style="color: #808080;">.</span>ProductID <span style="color: #808080;">= </span>PV<span style="color: #808080;">.</span>ProductID<span style="color: #808080;">)</span></pre>
<pre class="code"></pre>
<p>Keep this tip in mind.  It will save you heartache throughout your next project.</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:2089731e-2353-4b16-84f0-235d0d727151" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/10/sql-tip-uniquely-name-table-columns/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Code Generation with Stored Procedures?</title>
		<link>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/</link>
		<comments>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 20:49:40 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SubSonic]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/</guid>
		<description><![CDATA[I very recently posted about using SubSonic to generate my DAL and SSMS Tool Pack to generate the complementing stored procedures.  In response to the post, Jon Galloway asked a great question in the comments: Thanks for the pointer to SSMS Tool Packs. It looks really interesting. One thing I’m having trouble picturing is the [...]]]></description>
			<content:encoded><![CDATA[<p>I very recently posted about using <a href="http://johnnycoder.com/blog/2008/05/21/subsonic-and-ssms-tools-pack-saved-the-day/">SubSonic to generate my DAL and SSMS Tool Pack to generate the complementing stored procedures</a>.  In response to the post, <a href="http://weblogs.asp.net/jgalloway/">Jon Galloway</a> asked a great question in the comments:</p>
<blockquote><p>Thanks for the pointer to SSMS Tool Packs. It looks really interesting. One thing I’m having trouble picturing is the overlap between the two [SubSonic and SSMS Tool Pack]. Once you have a DAL, what do you need CRUD routines for? Bulk operations, or something that’s a result of the existing architecture?</p></blockquote>
<p>For those familiar with SubSonic you can appreciate Jon&#8217;s question.  Since SubSonic&#8217;s generated DAL provides you with CRUD methods and easily allows you build resulting parameterized queries, you are no longer dependent upon having compiled routines sitting in the database. </p>
<p>Almost on queue, Caffeinated Coder recently a great article on why one should &#8220;<a href="http://www.caffeinatedcoder.com/just-say-no-to-manual-crud/">Just Say No to Manual CRUD</a>&#8221; which provide a list of resources which present good counter arguments against the conventional stored proc wisdom.</p>
<p>So, why the heck am I still using stored procedures?</p>
<p>If I were to be honest, the number one reason I&#8217;m sticking with SPs is they are familiar and they provide me with a sense of comfort.  Most of my uneasiness with &#8220;embedding&#8221; data access into the application code is tied to deployment and maintenance.  For example, I like to have multiple &#8220;outs&#8221; when it comes to rollbacks and I like to keep emergency fixes as isolated as possible. Since stored procedures could be considered more atomic than even the most lightweight DLL, I can update a live application by altering a single stored procedure with more confidence than copying/replacing application file(s.)  Assuming you have a single database and a web application running on multiple web servers, in my opinion, the stored procedure update is best solution since time to implement is low, risk is minimal and downtime is eliminated. </p>
<p>I had a good follow up conversation with Jon about all of this last week and the bottom-line is that one needs to put the right architecture in place based on their coding, deployment and maintenance needs.  I am currently sticking with stored procedures but this approach isn&#8217;t necessarily right for everyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/06/02/code-generation-with-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Mix DDL and DML</title>
		<link>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/</link>
		<comments>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 03:16:28 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/</guid>
		<description><![CDATA[I sat through an absolutely fantastic presentation on query optimization a couple of weeks back.  The presenter did a fine job of covering many of the basics like SET NOCOUNT ON, minimize cursor use, avoid explicit or implicit functions in the WHERE clause and why not to use the sp_ prefix when naming custom stored [...]]]></description>
			<content:encoded><![CDATA[<p>I sat through an absolutely fantastic presentation on query optimization a couple of weeks back.  The presenter did a fine job of covering many of the basics like <span style="color: #0000ff;">SET</span> NOCOUNT <span style="color: #0000ff;">ON</span>, minimize cursor use, avoid explicit or implicit functions in the <span style="color: #0000ff;">WHERE </span>clause and why not to use the sp_ prefix when naming custom stored procedures.  He also touched upon practices which are critical aspects of query optimization, yet, in my opinion, few put into practice. Specifically, he talked about the need for benchmarks and how to establish them.  He also demonstrated how to conduct sufficient testing.  Then there were the more advanced topics like table fragmentation, associated DBCC commands, Statistics IO, Fill Factor and how procedure cache works.  He also shared plenty of TSQL samples and how they will (or will not) use a given index.  For example, did you know the LIKE clause can use indexes if the pattern starts with a character string such as <span style="color: #0000ff;">WHERE</span> lname <span style="color: #808080;">LIKE</span> <span style="color: #ff0000;">&#8216;W%&#8217;</span> but LIKE cannot use an index if the pattern starts with a leading wildcard, such as <span style="color: #0000ff;">WHERE</span> lname <span style="color: #808080;">LIKE </span><span style="color: #ff0000;">&#8216;%wold&#8217;</span>?  Again, excellent presentation and did I mention it was wrapped up in under an hour? </p>
<p>I typically roll the dice with these types of presentation knowing they may turn out to be a refresher course, way over my head, or worse, an absolute bore.  This one was worth sitting through as I picked up the following nugget: <strong>Mixing DDL and DML Operations Can Cause a Recompile</strong>.</p>
<p>What does this mean?  DDL (Data Definition Language) and DML (Data Manipulation Language) almost always exists in our stored procedures.  Examples of DDL are our <span style="color: #0000ff;">DECLARE </span>variable and <span style="color: #0000ff;">CREATE</span> <span style="color: #0000ff;">TABLE </span>statements.  DML, on the other hand, includes our <span style="color: #0000ff;">SET</span><span style="color: #808080;">,</span> <span style="color: #0000ff;">SELECT </span>and <span style="color: #0000ff;">INSERT </span>to name a few.  A key cause of stored procedure recompiles is the interleaving of DML and DDL statements &#8212; especially DDL following DML statements.  In other words, according to Microsoft best practices, place all of your DDL statements at the top of your stored procedures and then do your actual query work. Now, are recompiles always going to happen if you have interleaved DDL and DML?  Nope, not in all case, but you should do everything possible to prevent recompiles (even if it is super easy.)</p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:7264d5d9-d6ce-4eb8-a333-4bdff3c2b4ed" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/02/05/dont-mix-ddl-and-dml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Coping with Windows Auth</title>
		<link>http://johnnycoder.com/blog/2007/08/30/coping-with-windows-auth/</link>
		<comments>http://johnnycoder.com/blog/2007/08/30/coping-with-windows-auth/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 10:02:21 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2007/08/30/coping-with-windows-auth/</guid>
		<description><![CDATA[There are a few primary reasons why Windows Authentication should be considered a best practice. Since passwords aren&#8217;t visibly exposed in configuration files and credentials are not sent over the network, your systems tend to be more secure.  Additionally, password management (expiration periods, minimum lengths and account lockout after multiple invalid logon requests) becomes a heck [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few primary reasons why Windows Authentication should be considered a best practice. Since passwords aren&#8217;t visibly exposed in configuration files and credentials are not sent over the network, your systems tend to be more secure.  Additionally, password management (expiration periods, minimum lengths and account lockout after multiple invalid logon requests) becomes a heck of a lot easier. Considering the benefits, I have no issues with <span style="text-decoration: underline;">applications</span> accessing SQL Server using Integrated Security, however, I think there is a big different between application access and <span style="text-decoration: underline;">developer</span> access. </p>
<p>Really quickly, you can setup SQL Server to run in one of two security modes: Windows Authentication or Mixed Mode.  Mixed Mode is exactly as it implies and allows users to connect using Windows NT Authentication or using SQL Server Authentication.  I&#8217;m a fan of Mixed Mode which allows for application accounts to reap the benefits of Integrated Security while allowing considerably easier SQL Auth access for developers, support personnel, etc. </p>
<p>Please consider the following scenarios: </p>
<ol>
<li>An instance of SQL Server is setup in the Development Environment and it isn&#8217;t running in Mixed Mode.  This implies that one needs to be a member of the appropriate domain and have appropriate permissions in order to access the SQL Server.  Not a big deal, right?  Well, I would agree if I were a developer working onsite and the Dev Network was readily available to me. But I happen to work remotely on occasion and there isn&#8217;t an entrance point into this particular domain through VPN.  Boy, SQL Authentication sure would come in handy in this case. </li>
<li>Let&#8217;s say your environments (perhaps Dev, QA and Production) are hosted in separate domains.  It would be painful to switch between domains in order to access each SQL Servers, wouldn&#8217;t it?  (I know what you are thinking, &#8220;Why would a developer need to access QA or Production?&#8221;  Special assignment.  Let&#8217;s leave it at that.)</li>
</ol>
<p>Fortunately, there&#8217;s a workaround.  If you are me, you beg and plead and moan and request that security mode be changed (not that that&#8217;s easy.) OR you discover an even better solution in the appropriately named <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true">RunAs</a> command which allows a user to run specific tools and programs with different permissions than the user&#8217;s current logon provides.  </p>
<p>The following are a few of  my favorite commands which I&#8217;ve wrapped up neatly in their own .cmd file for quick execution (you will need to update the domain and user values accordingly):</p>
<ul>
<li>runas /user:domain\user &#8220;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\ssmsee.exe&#8221;</li>
<li>runas /user:domain\user &#8220;C:\WINDOWS\system32\mmc.exe /s \&#8221;C:\Program Files\Microsoft SQL Server\80\Tools\BINN\SQL Server Enterprise Manager.MSC\&#8221;"</li>
<li>runas /user:domain\user isqlw</li>
</ul>
<p>This tip actually came from a wise, remote developer working in Canada who was confronted with Scenario 1 above.  Pretty neat, eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2007/08/30/coping-with-windows-auth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DBTalk &#8211; Avoid Functions in the WHERE Clause</title>
		<link>http://johnnycoder.com/blog/2007/08/04/dbtalk-avoid-functions-in-the-where-clause/</link>
		<comments>http://johnnycoder.com/blog/2007/08/04/dbtalk-avoid-functions-in-the-where-clause/#comments</comments>
		<pubDate>Sat, 04 Aug 2007 21:32:40 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2007/08/04/dbtalk-avoid-functions-in-the-where-clause/</guid>
		<description><![CDATA[Functions like &#8220;getdate()&#8221; and convert(varchar(10), MyDateColumn,101) commonly show up in the WHERE clause of queries.  Here&#8217;s an example: select   c.LastName from     Customer c with (nolock) where    c.LastUpdated &#60; getdate() You might think &#8220;no big deal.&#8221; It&#8217;s just a function, but for sql server, it almost always turns a deterministic query into a non-deterministic one.  The [...]]]></description>
			<content:encoded><![CDATA[<p>Functions like &#8220;getdate()&#8221; and convert(varchar(10), MyDateColumn,101) commonly show up in the WHERE clause of queries.  Here&#8217;s an example:</p>
<p><span style="color: #0000ff">select</span>   c<span style="color: #808080">.</span>LastName<br />
<span style="color: #0000ff">from</span>     Customer c <span style="color: #0000ff">with</span> <span style="color: #808080">(</span>nolock<span style="color: #808080">)<br />
</span><span style="color: #0000ff">where</span>    c<span style="color: #808080">.</span>LastUpdated <span style="color: #808080">&lt;</span> <span style="color: #ff00ff">getdate</span><span style="color: #808080">()</span></p>
<p>You might think &#8220;no big deal.&#8221; It&#8217;s just a function, but for sql server, it almost always turns a deterministic query into a non-deterministic one.  The difference?  Index usage.</p>
<p>Most of the time, sql server will ignore any index on a column that is used in a WHERE clause expression containing a function, turning an index seek into an index or table scan, with the obvious performance penalty.</p>
<p>So instead of the above query, replace it with:</p>
<pre class="code"><span style="color: #0000ff">declare</span>  @CurrentDate <span style="color: #0000ff">datetime
select</span>   @CurrentDate <span style="color: #808080">=</span> <span style="color: #ff00ff">getdate</span><span style="color: #808080">()   

</span><span style="color: #0000ff">select</span>   c<span style="color: #808080">.</span>LastName
<span style="color: #0000ff">from</span>     Customer c <span style="color: #0000ff">with</span> <span style="color: #808080">(</span>nolock<span style="color: #808080">)
</span><span style="color: #0000ff">where</span>    c<span style="color: #808080">.</span>LastUpdated <span style="color: #808080">&lt;</span> @CurrentDate</pre>
<p>The function is gone and sql server will use an index on LastUpdated if it exists.</p>
<p>The same holds true for this example:</p>
<pre class="code"><span style="color: #0000ff">select</span>   c<span style="color: #808080">.</span>LastName
<span style="color: #0000ff">from</span>     Customer c <span style="color: #0000ff">with</span> <span style="color: #808080">(</span>nolock<span style="color: #808080">)
</span><span style="color: #0000ff">where</span>    c<span style="color: #808080">.</span>LastUpdated <span style="color: #808080">&lt;</span> <span style="color: #ff00ff">dateAdd</span><span style="color: #808080">(</span><span style="color: #ff00ff">day</span><span style="color: #808080">,</span> <span style="color: #808080">-</span>1<span style="color: #808080">,</span> <span style="color: #ff00ff">getdate</span><span style="color: #808080">())
</span></pre>
<pre class="code">becomes:</pre>
<p><span style="color: #0000ff">declare</span>  @CurrentDate <span style="color: #0000ff">datetime<br />
select</span> @CurrentDate <span style="color: #808080">=</span> <span style="color: #ff00ff">dateAdd</span><span style="color: #808080">(</span><span style="color: #ff00ff">day</span><span style="color: #808080">,</span> <span style="color: #808080">-</span>1<span style="color: #808080">,</span> <span style="color: #ff00ff">getdate</span><span style="color: #808080">())</span><span style="color: #808080"><span style="color: #808080"><span style="color: #0000ff">select</span>   c<span style="color: #808080">.</span>LastName<br />
<span style="color: #0000ff">from</span>     Customer c <span style="color: #0000ff">with</span> <span style="color: #808080">(</span>nolock<span style="color: #808080">)<br />
</span><span style="color: #0000ff">where</span>    c<span style="color: #808080">.</span>LastUpdated <span style="color: #808080">&lt;</span> @CurrentDate</p>
<p></span><span style="color: #808080">Sometimes there is simply no workaround for a function in the WHERE clause but, knowing their impact, make every effort to eliminate them. </span></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2007/08/04/dbtalk-avoid-functions-in-the-where-clause/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DBTalk</title>
		<link>http://johnnycoder.com/blog/2007/08/04/dbtalk/</link>
		<comments>http://johnnycoder.com/blog/2007/08/04/dbtalk/#comments</comments>
		<pubDate>Sat, 04 Aug 2007 20:10:23 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Management]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Team]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2007/08/04/dbtalk/</guid>
		<description><![CDATA[Over the past 6 months, I&#8217;ve subscribed to the &#8220;DBTalk&#8221; distribution list at work and I&#8217;ve really been enjoying it.  Here&#8217;s are my top 2 reasons: 1. Though I know there are many .NET coders who also happen to be very capable database designers and developers, I believe that the many of us still have a lot to [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past 6 months, I&#8217;ve subscribed to the &#8220;DBTalk&#8221; distribution list at work and I&#8217;ve really been enjoying it.  Here&#8217;s are my top 2 reasons:</p>
<p>1. Though I know there are many .NET coders who also happen to be very capable database designers and developers, I believe that the many of us still have a lot to learn.  I would say that we all know at least the basics, but there&#8217;s an awful lot of DB knowledge that has eludes us over the years.  If nothing else, the &#8220;DBTalk&#8221; distribution list has proven to be a non-intrusive way to educate an entire group of developers on SQL Server Best Practices and a few Tips &amp; Tricks.</p>
<p>2. The moderator does a really nice job of getting everyone involved.  Those of us who frequent technical blogs know this isn&#8217;t always easy &#8212; especially when your audience isn&#8217;t necessarily comfortable with the topic.  Fortunately, the moderate provides information on varying topics for all levels and he throws out carrots all the time.  For example, he&#8217;ll present a Tip of the Day and ask if anyone has an alternative solution or he will simply submit a problem and ask for possible solutions.  It seems with most conversation at least someone on the distribution list is willing to bite.</p>
<p>Anyhow, with permission, I&#8217;ll be posting a number of the topics and tips which have been discussed over the past several months.  They may come all at once, in chunks or one every once in a while.  I haven&#8217;t yet decided.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2007/08/04/dbtalk/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>What&#8217;s the Best Way to Manage a Database Queue?</title>
		<link>http://johnnycoder.com/blog/2007/06/20/whats-the-best-way-to-manage-a-database-queue/</link>
		<comments>http://johnnycoder.com/blog/2007/06/20/whats-the-best-way-to-manage-a-database-queue/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 03:09:17 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Library]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2007/06/20/whats-the-best-way-to-manage-a-database-queue/</guid>
		<description><![CDATA[This question circulates through the office about once a year.  &#8220;Um, I have Windows service which processes requests which are queued in a database table.  Everything is working great, but I would like to add a second instance of the service and I need to know the best way to ensure the services don&#8217;t step [...]]]></description>
			<content:encoded><![CDATA[<p>This question circulates through the office about once a year.  &#8220;Um, I have Windows service which processes requests which are queued in a database table.  Everything is working great, but I would like to add a second instance of the service and I need to know the best way to ensure the services don&#8217;t step on each other.  In other words, how do I mark each row as it is being processed so it won&#8217;t be picked up again?&#8221; </p>
<p>Here are the ingredients in my current ideal solution:</p>
<ol>
<li>The table must include the following columns: a Unique Identifier such as RequestID, Status, LockedBy, and LockedTime.  I also like to include RequestedTime and CompletionTime columns as I&#8217;ve found that capturing these values help when/if system stats are required.</li>
<li>The key is to lock the current request at the time of processing.  To do so, you should use a transaction and an update lock.</li>
<li>I think it is important to pull requests off the queue in an intelligent order.  FIFO is the best bet under most circumstances.  In this case, the RequestedTime column becomes imperative (unless your RequestID is an auto-incrementing identity column and you are comfortable ordering on it.)</li>
<li>Finally, I like to make sure no request is left behind.  Let&#8217;s say Service A locks a request for processing and then the application server crashes.  I want the lock to eventually expire so Service B can pick up the row and save the day.</li>
</ol>
<p>Assuming new requests are added to the queue as &#8216;Pending&#8217; , one may use a routine similar to the one below to safely pull the next request off the queue:</p>
<pre class="code"><span style="color: #0000ff;">create</span> <span style="color: #0000ff;">procedure</span> [GetNextItemInQueue]
<span style="color: #808080;">(
</span>    @LockedBy varchar<span style="color: #808080;">(</span>75<span style="color: #808080;">)
)
</span><span style="color: #0000ff;">as 

set</span> nocount <span style="color: #0000ff;">on 

declare</span>
    @Error                     <span style="color: #0000ff;">int</span><span style="color: #808080;">,
</span>    @ExitCode                  <span style="color: #0000ff;">int</span><span style="color: #808080;">,
</span>    @RowCount                  <span style="color: #0000ff;">int</span><span style="color: #808080;">,
</span>    @PendingStatus               <span style="color: #0000ff;">int</span><span style="color: #808080;">,
</span>    @MinutesBeforeBreakLock       <span style="color: #0000ff;">int</span><span style="color: #808080;">,
</span>    @RequestId                   <span style="color: #0000ff;">int
</span>
<span style="color: #0000ff;">select</span>
    @Error                      <span style="color: #808080;">=</span> 0<span style="color: #808080;">,
</span>    @ExitCode                   <span style="color: #808080;">=</span> 0<span style="color: #808080;">,
</span>    @RowCount                   <span style="color: #808080;">=</span> 0<span style="color: #808080;">,
</span>    @PendingStatus                <span style="color: #808080;">=</span> 1<span style="color: #808080;">,
</span>    @MinutesBeforeBreakLock        <span style="color: #808080;">=</span> 30 

<span style="color: #0000ff;">begin</span> <span style="color: #0000ff;">tran</span> ProcessQueue 

<span style="color: #0000ff;">select</span> <span style="color: #0000ff;">top</span> 1 @RequestId <span style="color: #808080;">=</span> RequestId
<span style="color: #0000ff;">from</span> Queue <span style="color: #0000ff;">with</span> <span style="color: #808080;">(</span>updlock<span style="color: #808080;">)
</span><span style="color: #0000ff;">where</span> Status <span style="color: #808080;">=</span> @PendingStatus
<span style="color: #808080;">and</span> <span style="color: #808080;">(</span>LockedTime <span style="color: #808080;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #808080;">OR</span>
<span style="color: #ff00ff;">DateDiff</span><span style="color: #808080;">(</span>mi<span style="color: #808080;">,</span> LockedTime<span style="color: #808080;">,</span> <span style="color: #ff00ff;">GetDate</span><span style="color: #808080;">())</span> <span style="color: #808080;">&gt;=</span> @MinutesBeforeBreakLock<span style="color: #808080;">)
</span><span style="color: #0000ff;">order</span> <span style="color: #0000ff;">by</span> RequestedTime <span style="color: #0000ff;">Asc 

select</span> @RowCount <span style="color: #808080;">=</span> <span style="color: #ff00ff;">@@RowCount</span><span style="color: #808080;">,</span> @Error <span style="color: #808080;">=</span> <span style="color: #ff00ff;">@@Error 

</span><span style="color: #0000ff;">if</span> <span style="color: #808080;">(</span>@RowCount <span style="color: #808080;">=</span> 0<span style="color: #808080;">)
</span>    <span style="color: #0000ff;">goto</span> ExitProc 

<span style="color: #0000ff;">if</span> <span style="color: #808080;">(</span>@Error <span style="color: #808080;">&lt;&gt;</span> 0<span style="color: #808080;">)
</span>    <span style="color: #0000ff;">goto</span> ErrorHandler 

<span style="color: #0000ff;">update</span> Queue
<span style="color: #0000ff;">set</span>    LockedBy <span style="color: #808080;">=</span> @LockedBy<span style="color: #808080;">,</span>
    LockedTime <span style="color: #808080;">=</span> <span style="color: #ff00ff;">GetDate</span><span style="color: #808080;">()
</span><span style="color: #0000ff;">where</span> RequestId <span style="color: #808080;">=</span> @RequestId 

<span style="color: #0000ff;">select</span> @Error <span style="color: #808080;">=</span> <span style="color: #ff00ff;">@@Error
</span><span style="color: #0000ff;">if</span> <span style="color: #808080;">(</span>@Error <span style="color: #808080;">&lt;&gt;</span> 0<span style="color: #808080;">)
</span>    <span style="color: #0000ff;">goto</span> ErrorHandler 

<span style="color: #0000ff;">select</span> @RequestId <span style="color: #0000ff;">as</span> RequestId 

<span style="color: #0000ff;">select</span> @Error <span style="color: #808080;">=</span> <span style="color: #ff00ff;">@@Error
</span><span style="color: #0000ff;">if</span> <span style="color: #808080;">(</span>@Error <span style="color: #808080;">&lt;&gt;</span> 0<span style="color: #808080;">)
</span>    <span style="color: #0000ff;">goto</span> ErrorHandler 

<span style="color: #0000ff;">goto</span> ExitProc 

ErrorHandler<span style="color: #808080;">:
</span>    <span style="color: #0000ff;">raiserror</span>   <span style="color: #808080;">(</span>@Error<span style="color: #808080;">,</span> 16<span style="color: #808080;">,</span> 1<span style="color: #808080;">)
</span>    <span style="color: #0000ff;">if</span> <span style="color: #ff00ff;">@@trancount</span> <span style="color: #808080;">&gt;</span> 0
        <span style="color: #0000ff;">rollback</span> <span style="color: #0000ff;">tran</span> ProcessQueue
    <span style="color: #0000ff;">select</span>      @ExitCode <span style="color: #808080;">=</span>  <span style="color: #808080;">-</span>100 

ExitProc<span style="color: #808080;">:
</span>    <span style="color: #0000ff;">commit</span> <span style="color: #0000ff;">tran</span> ProcessQueue
    <span style="color: #0000ff;">return</span>      <span style="color: #808080;">(</span>@ExitCode<span style="color: #808080;">)</span></pre>
<p>Once the request is processed, a database call will be made to update the row&#8217;s Status to &#8216;Complete&#8217; and CompletionTime. </p>
<p>Note, you may choose to change the status of each row from &#8216;Pending&#8217; to &#8216;Processing&#8217; when you do the initial lock.  This is perfectly fine, but I&#8217;ve found that is unnecessary as the Processing status can be determined based on the value of other columns.</p>
<p>Again, that&#8217;s my current preferred implementation.  Perhaps there are better solutions out there?</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2007/06/20/whats-the-best-way-to-manage-a-database-queue/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>SQL 2005 Installation Issues &#8230; Again</title>
		<link>http://johnnycoder.com/blog/2006/11/15/sql-2005-installation-issues-again/</link>
		<comments>http://johnnycoder.com/blog/2006/11/15/sql-2005-installation-issues-again/#comments</comments>
		<pubDate>Wed, 15 Nov 2006 16:56:03 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[Brain Scratcher]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/11/15/sql-2005-installation-issues-again/</guid>
		<description><![CDATA[I picked up a new development box the other day and I spent most of yesterday (heck, it was ALL of yesterday) getting the machine configured. Nearly all software installed without any issues except for SQL Server 2005 Developer Edition. After completing the installation, I planned to validate the installation by first checking to see [...]]]></description>
			<content:encoded><![CDATA[<p>I picked up a new development box the other day and I spent most of yesterday (heck, it was ALL of yesterday) getting the machine configured. Nearly all software installed without any issues except for SQL Server 2005 Developer Edition. After completing the installation, I planned to validate the installation by first checking to see that the SQL Server services were running and then launching SQL Server Management Studio to ensure I could connect to the Northwind database. The services were running, however, there wasn&#8217;t much to be found other than Configuration Tools under Programs &gt; Microsoft SQL Server 2005. <a href="http://johnnycoder.com/blog/wp-content/uploads/2006/11/WindowsLiveWriter/NewDevelopmentBox_7204/10%5B2%5D.png"><img style="margin: 5px 13px 0px 3px" src="http://johnnycoder.com/blog/wp-content/uploads/2006/11/WindowsLiveWriter/NewDevelopmentBox_7204/10_thumb%5B2%5D.png" alt="" width="450" height="110" align="left" /></a></p>
<p>This wasn&#8217;t the first time this installation gave me trouble. In fact, the screen shot above comes from one of my laptops which I opted not to &#8220;patch.&#8221; But since I was surely going to need SQL installed on the new machine, I didn&#8217;t have the luxury of abandoning the installation this time around.</p>
<p>I attempted to install a few times with no luck. I googled for help with little luck. In the end, I uninstalled every &#8220;Microsoft SQL Server&#8230;&#8221; program and then reinstalled. It worked! I assumed this attempt was successful because I had uninstalled a version of SQL Server 2005 Express along with all the other programs. A google search implied that this may be causing the issues. However, the laptop which I still haven&#8217;t patched doesn&#8217;t have the Express Edition running.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2006/11/WindowsLiveWriter/NewDevelopmentBox_7204/91.png"><img style="margin: 5px 13px 0px 3px" src="http://johnnycoder.com/blog/wp-content/uploads/2006/11/WindowsLiveWriter/NewDevelopmentBox_7204/9_thumb1.png" alt="" width="315" height="150" align="left" /></a></p>
<p>I&#8217;m not sure if I&#8217;ll ever figure this one out. Actually, I&#8217;m not sure if I want to. I know well over a dozen individuals who have successfully installed SQL 2005 without any problems and now I have botched up the installation on two separate occasions on two different machines using two different installation discs. I&#8217;m either unlucky, cursed or dumb (or a combination of the three) and I don&#8217;t care to know which&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/11/15/sql-2005-installation-issues-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrated Authentication Gotchas</title>
		<link>http://johnnycoder.com/blog/2006/10/27/integrated-authentication-gotchas/</link>
		<comments>http://johnnycoder.com/blog/2006/10/27/integrated-authentication-gotchas/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 19:39:36 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/10/27/integrated-authentication-gotchas/</guid>
		<description><![CDATA[We are currently going through the exercise of converting our web applications (primarily .NET web applications) from SQL Server Authentication over to Integrated Authentication. Integrated authentication allows for SQL Server to leverage Windows NT authentication to validate SQL Server logon accounts. This allows the user to bypass the standard SQL Server logon process. With this approach, [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently going through the exercise of converting our web applications (primarily .NET web applications) from SQL Server Authentication over to Integrated Authentication.</p>
<p>Integrated authentication allows for SQL Server to leverage Windows NT authentication to validate SQL Server logon accounts. This allows the user to bypass the standard SQL Server logon process. With this approach, a network user can access a SQL Server database without supplying a separate logon identification or password because SQL Server obtains the user and password information from the Windows NT network security process.</p>
<p>Choosing integrated authentication for ASP.NET applications is a good choice because no credentials are ever stored within your connection string for your application.   Thus, security is improved.  Another reason to incorporate Integrated Authentication is to facilitate account and password policy enforcement through a domain controller.  For example, this might require passwords be recycled every 90 days.</p>
<p>&#8220;Integrated Authentication is not difficult to implement.&#8221;  I&#8217;ve heard this time and time again.  Actually, in an ideal scenario, this is a correct statement and the implementation requires just a few steps:</p>
<p>1. Set SQL Server Authentication to Mixed Mode.</p>
<p>2. Set identity impersonate to true and assign the username and password in the IIS.</p>
<p>3. Update you connection string to use one of the following variations:</p>
<p>    a. data source=myServer;initial catalog=myDB;Integrated Security=SSPI <br />
    b. server=myServer; database=myDB;Trusted_Connection=true</p>
<p>Easy, right?  Sure.  But what if you are <span style="text-decoration: underline;">converting</span> to NT Authentication and your existing network and application(s) are not ideally setup?  In this case, there are a number of potential (read probable) gotchas. </p>
<p>There are three obstacles I wish to discuss, but today I am going to focus on one of them. This issue is the most obscure and I would bet that the majority of those tasked with estimating a conversion to NT Authentication would not even consider this condition.  I&#8217;m also calling attention to this gotcha first because, in my opinion, it comes with painless and noteworthy solution.</p>
<h2>Gotcha # 1:</h2>
<p>Our web applications call upon a number of Windows Services.  These services should be considered legacy components.  They have been around for a while and they continue to do their job so they get little attention.  Each of these components store connection string information in the registry. </p>
<p>As you have noticed, connection string formats vary based on the authentication method.</p>
<p><strong>Integrated Authentication<br />
</strong>data source=myServer;initial catalog=myDB;Integrated Security=SSPI;</p>
<p><strong>SQL Server Authentication:<br />
</strong>data source=myServer; initial catalog=myDB; user id=myUsername; password=myPassword; </p>
<p>In this case, the registry held the four primary SQL Server connection parameters and the service would use the associated values to build the string on the fly.  Can you see where this is going?   Fortunately, we identified this little issue early on and we estimated time to rework the functionality, rebuild, test and redeploy the services.  This was risky since these services were rarely modified/deployed and it was going to be expensive since there were more than a dozen services which required these changes.</p>
<p>This was until a colleague of mine uncovered an elegant hack. [Is that an oxymoron?]  He discovered that once the <em>Integrated Security</em> parameter of the connection string is set to <em>SSPI</em> parameters such as User ID and Password are virtually ignored.  (He also found out that extra semi-colons don&#8217;t make a lick of difference either.) </p>
<p>In the end, we hacked our registry entries to allow our services to build and use NT Auth compliant connection strings. </p>
<p><strong><em>Sample registry entries:</em></strong></p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2006/10/WindowsLiveWriter/ConvertingtoNTAuth_82BC/24%5B1%5D.png"><img style="margin: 5px 13px 0px 3px" src="http://johnnycoder.com/blog/wp-content/uploads/2006/10/WindowsLiveWriter/ConvertingtoNTAuth_82BC/24_thumb%5B1%5D.png" alt="" width="372" height="115" align="left" /></a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><strong><em>Resulting connection string:</em></strong></p>
<p>datasource=myServer;integrated security=SSPI;initial catalog=myDB;user id=;password=;</p>
<p>This reduced risk and simplified our deployment to modifications to the registry through the execution of a single .reg script. </p>
<p>Opening up the services and redeploying may have been the best solution, but this hack got the job done safely and effectively and on the cheap.  And we learned a bit more about how connection strings work.  Who knows?  This tip may help you out of a pinch someday.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/27/integrated-authentication-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Take Advantage of Application Name</title>
		<link>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</link>
		<comments>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 07:44:21 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</guid>
		<description><![CDATA[Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver.       Data Source=myServer;      Initial Catalog=myDB;      User Id=myUsername;      Password=myPassword;      Application Name=myApp; Consider this example:  There are multiple .NET applications running on a single web server.  Each application [...]]]></description>
			<content:encoded><![CDATA[<p>Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver. </p>
<p><em>     Data Source=myServer;<br />
     Initial Catalog=myDB;<br />
     User Id=myUsername;<br />
     Password=myPassword;<br />
     <strong>Application Name=myApp;</strong></em></p>
<p>Consider this example:  There are multiple .NET applications running on a single web server.  Each application shares a common SQL Server Server which is suddenly performing very poorly.   You are tasked with determine which of the applications is causing havoc.  You launch SQL Profiler and run a trace.  Since you have included the optional parameter in your connection string, you may now filter the application specific queries and troubleshoot the problem far more effectively.  If you hadn&#8217;t specified the application name, you would have some work ahead of you.  In this case, all of the queries would have had a generic app name, <em>.NET sqlClient Data Provider</em>, and that isn&#8217;t very helpful, is it?  </p>
<p>Do yourself a favor and be sure to add this practice to your coding standards&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

