<?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>PeterKellner.net &#187; Sql Server</title>
	<atom:link href="http://peterkellner.net/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 11 May 2012 16:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Gaining Some Control Back From Microsoft&#8217;s Entity Framework Code First, Name Your Own Foreign Keys!</title>
		<link>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys</link>
		<comments>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 01:32:18 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/</guid>
		<description><![CDATA[Being a relative newbie to Microsoft’s Entity Framework Code First, there are things that I don’t like, things that I don’t understand, and well, just things that really bug me.&#160; The problem is I often find out that the things that I don’t like and bug me are often lack of knowledge and not lack [...]]]></description>
			<content:encoded><![CDATA[<p>Being a relative newbie to <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft’s</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/hh134698">Code First</a>, there are things that I don’t like, things that I don’t understand, and well, just things that really bug me.&#160; The problem is I often find out that the things that I don’t like and bug me are often lack of knowledge and not lack of product (at least not easily discoverable in the product).&#160; One of those things is that Code First makes up names for foreign keys that don’t happen to be the same name as I would use.&#160; Since there are times when you will need to look at these names (and possibly code with them (for another post)), I would like those names to be my names.</p>
<p>Let’s say you have a simple relationship between two tables.&#160; Let’s call it User and Address.&#160; Let’s just say for simplicity a user has one address.&#160; In CodeFirst, you would model it with tables like the following:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> User
{
        [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Address Address { get; set; }
       <span class="rem">// more details about user, name, etc.</span>
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
       [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
        <span class="rem">// more details about address, state,zip,etc.</span>
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, you will end up with an Address table that has a column named something like User_Id.&#160;&#160; YUC!!!&#160; Who puts underscores in column names anymore (well, certainly I don’t.</p>
<p>You may think all you need to do to solve this is put a foreign key column and attribute in the Address table as follows:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
     [Key]
     <span class="kwrd">public</span> <span class="kwrd">long</span> Id {get;set;}

     [ForeignKey]
     <span class="kwrd">public</span> <span class="kwrd">long</span> UserId {get;set;}

     <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
}</pre>
<p>But, when you do that, you will be greeted with an error that looks like the following:</p>
<blockquote>
<h4><i>System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role &#8216;EmailAccount_User_Source&#8217; in relationship &#8216;EmailAccount_User&#8217;. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be &#8216;*&#8217;.</i></h4>
</blockquote>
<p>or</p>
<blockquote>
<h4><i>The ForeignKeyAttribute on property &#8216;UserId&#8217; on type &#8216;EFCodeFirstLib.CodeFirstModels.EmailAccount&#8217; is not valid. The navigation property &#8216;User&#8217; was not found on the dependent type &#8216;EFCodeFirstLib.CodeFirstModels.EmailAccount&#8217;. The Name value should be a valid navigation property name.</i></h4>
</blockquote>
<p>&#160;</p>
<p>Pretty clear what to do, huh?</p>
<p>Well, I suppose if you know EF EDMX and a whole bunch of other acronyms, you probably will figure it out, but if you don’t I’ll tell you.&#160; You basically need to include the User property in your Address class.&#160; It should then look like:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Address
{
  [Key]
  <span class="kwrd">public</span> <span class="kwrd">long</span> Id {get;set}

  <span class="kwrd">public</span> User User {get;set;}  <span class="rem">// important!</span>
  [ForeignKey]
  <span class="kwrd">public</span> <span class="kwrd">long</span> UserId {get;set;}

  <span class="kwrd">public</span> <span class="kwrd">string</span> City {get;set;}
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>And now, you will have a “properly” named foreign key column “UserId” with no underscores!</p>
<p>My 2Cents.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/07/gaining-some-control-back-from-microsofts-entity-framework-code-first-name-your-own-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework CodeFirst Important Tip For SQL Execution Efficiency</title>
		<link>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entity-framework-codefirst-important-tip-for-sql-execution-efficiency</link>
		<comments>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 18:24:27 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/</guid>
		<description><![CDATA[&#160;
Introduction
&#160;
I’ve now been using Microsoft’s&#160;Entity Framework CodeFirst for a month or two and am very impressed with how easily it is to access data in a type safe way.&#160; I also have noticed that I need to be extra careful about how I form my LINQ or I can accidentally cause the Sql Server to [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>&#160;</p>
<p>I’ve now been using <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft’s</a>&#160;<a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">Entity Framework</a> <a href="http://blogs.msdn.com/b/adonet/archive/tags/code+first/">CodeFirst</a> for a month or two and am very impressed with how easily it is to access data in a type safe way.&#160; I also have noticed that I need to be extra careful about how I form my LINQ or I can accidentally cause the <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">Sql Server</a> to do tons of extra work (tons meaning lots, not actually tons).</p>
<p>I’ll basically explain this with actual code snippets to demonstrate my point and help you understand what I’m talking about. Let’s say you have a set of classes representing your model that basically have a master record and an associated detail record that contains an reference to a table that hold images.&#160; That is, basically, something like this:</p>
<p>&#160;</p>
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">class</span> User
    {
        [Key]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> FirstName { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> ICollection&lt;AddressBookEntry&gt;
                        AddressBookEntries { get; set; }
     }

 <span class="kwrd">public</span> <span class="kwrd">class</span>    AddressBookEntry
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> ImageDetail ImageDetail { get; set; }
    }

<span class="kwrd">public</span> <span class="kwrd">class</span> ImageDetail
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }

        [Required(ErrorMessage = <span class="str">&quot;Image Without Data Means Nothing&quot;</span>)]
        [Column(TypeName = <span class="str">&quot;image&quot;</span>)]
        <span class="kwrd">public</span> <span class="kwrd">byte</span>[] ImageDataBytes { get; set; }
    }</pre>
<h2>The Goal For Your Query</h2>
<p>The goal for your <a href="http://msdn.microsoft.com/en-us/data/aa937723">EF</a> query is you want to create a simple image viewer web page.&#160; That is, you want to get the following information from your query that will list the address book of a given person.&#160; The columns you want back for each address book entry (of a given user) are as follows:</p>
<ul>
<ul>
<li>AddressBookEntry.Id</li>
<li>ImageDetail.Id</li>
</ul>
</ul>
<p>You don’t actually want the blob data itself because you will let the html img tag actually get the data for you.</p>
<p>&#160;</p>
<h2>The Wrong Way</h2>
<p>You are probably tempted to write a query that looks something like this:</p>
<pre class="csharpcode">var userAccount =
       db.Users.Where(a =&gt; a.Id == userIdIWant).
               Include(p =&gt; p.addressBookEntries.Select(o =&gt; o.ImageDetail).
                            FirstOrDefault();</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>The problem with this is if you have 4MB image in your ImageDetail table, it will all come down when you materialize your query.</p>
<p>&#160;</p>
<p>&#160;</p>
<h2>The Right Way</h2>
<p>&#160;</p>
<p>The correct way is to create a resulting anonymous object something like this:</p>
<pre class="csharpcode">var userAccount =
      db.Users.Where(a =&gt; a.Id == userIdIWantd).
              Include(p =&gt; AddressBookEntries.Select(o =&gt; o.ImageDetails).Select(p=&gt;<span class="kwrd">new</span> {
                 p.Id,
                 p.ImageDetails.Id
              }));</pre>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>&#160;</p>
<p>Sorry if the syntax here is not perfect.&#160; I did not actually use these tables, my problem is a little different, but I just wanted to get my point across about how important making anonymous (or staticly typed) result sets are for performance and how easily you can make code that will kill the performance of your server.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/05/entity-framework-codefirst-important-tip-for-sql-execution-efficiency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When Using EF CodeFirst With Visual Studio, How to Live With Cannot drop database because it is in use error.</title>
		<link>http://peterkellner.net/2012/01/15/when-using-ef-codefirst-with-visual-studio-how-to-live-with-cannot-drop-database-because-it-is-in-use-error/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=when-using-ef-codefirst-with-visual-studio-how-to-live-with-cannot-drop-database-because-it-is-in-use-error</link>
		<comments>http://peterkellner.net/2012/01/15/when-using-ef-codefirst-with-visual-studio-how-to-live-with-cannot-drop-database-because-it-is-in-use-error/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 18:58:50 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server CE]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/01/15/when-using-ef-codefirst-with-visual-studio-how-to-live-with-cannot-drop-database-because-it-is-in-use-error/</guid>
		<description><![CDATA[
Problem

So, if you have been doing development with Visual Studio 2010, Entity Framework CodeFirst, SqlServer or SqlServerCE for any amount of time, you’ll quickly run into the problem that the database can not be reinitialized because it is open.&#160; Basically, the scenario is this.
1)&#160; Put in your Global.asax.cs file a line that always recreates the [...]]]></description>
			<content:encoded><![CDATA[<h2>
<p>Problem</p>
</h2>
<p>So, if you have been doing development with <a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions">Visual Studio 2010</a>, <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=8363">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">CodeFirst</a>, <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> or <a href="http://en.wikipedia.org/wiki/SQL_Server_Compact">SqlServerCE</a> for any amount of time, you’ll quickly run into the problem that the database can not be reinitialized because it is open.&#160; Basically, the scenario is this.</p>
<p>1)&#160; Put in your <a href="http://msdn.microsoft.com/en-us/library/2027ewzw.aspx">Global.asax.cs</a> file a line that always recreates the database (naturally because you are in a development mode and as you constantly change your model and seed data).&#160; The line is something like this:&#160; Database.SetInitializer(new <a href="http://msdn.microsoft.com/en-us/library/gg679506(v=vs.103).aspx">DropCreateDatabaseAlways</a>&lt;SiteDB&gt;());</p>
<p>2)&#160; Run your application with something like Debug/Run (All is fine)</p>
<p>3)&#160; Go into the database browser (either in Visual Studio or Enterprise Manager)&#160; and look at some data.</p>
<p>4)&#160; Run your application again and you will get this error: “[SqlException (0x80131904): Cannot drop database &quot;NewYorkTimesDb&quot; because it is currently in use.]”.&#160; This is because your database browser has a connection to the database and until it is dropped, you can not drop the catalog.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/01/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/01/image_thumb7.png" width="574" height="199" /></a></p>
<p>&#160;</p>
<h2>Solutions</h2>
<p>&#160;</p>
<p>The easiest and guaranteed to work solution is just to restart your SqlServer database server (control panel, services).&#160; This is what I use to do but finally got tired of that because it takes about 20 seconds and, well, I’m very impatient.</p>
<p>The other solution <a href="http://stackoverflow.com/questions/11620/how-do-you-kill-all-current-connections-to-a-sql-server-2005-database">I found</a> in the forums (can’t find the link right now) is to execute the following script from the master database catalog:</p>
<pre class="csharpcode"><span class="kwrd">use</span> master
<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> NewYorkTimesDb
   <span class="kwrd">SET</span> SINGLE_USER <span class="kwrd">WITH</span> <span class="kwrd">ROLLBACK</span> <span class="kwrd">IMMEDIATE</span>
<span class="kwrd">ALTER</span> <span class="kwrd">DATABASE</span> NewYorkTimesDb <span class="kwrd">SET</span> MULTI_USER</pre>
<p>Basically, just switching from multi-user to single-user and back clears the connections.</p>
<p>HTH’s!<br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/01/15/when-using-ef-codefirst-with-visual-studio-how-to-live-with-cannot-drop-database-because-it-is-in-use-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip for Using SQLServer To Count By Alpha Names in a list</title>
		<link>http://peterkellner.net/2011/10/04/tip-for-using-sqlserver-to-count-by-alpha-names-in-a-list/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tip-for-using-sqlserver-to-count-by-alpha-names-in-a-list</link>
		<comments>http://peterkellner.net/2011/10/04/tip-for-using-sqlserver-to-count-by-alpha-names-in-a-list/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 05:11:33 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/10/04/tip-for-using-sqlserver-to-count-by-alpha-names-in-a-list/</guid>
		<description><![CDATA[&#160;
So, this is not a big tip, but worth at least 10 minutes to figure it out on your own.&#160; Here is to saving you 10 minutes:
&#160;

SELECT LEFT (userlastname, 1) as alpha,       count(id)FROM attendeesWHERE id IN (             [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>So, this is not a big tip, but worth at least 10 minutes to figure it out on your own.&#160; Here is to saving you 10 minutes:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">LEFT</span> (userlastname, 1) <span style="color: #0000ff">as</span> alpha,       <span style="color: #0000ff">count</span>(id)<span style="color: #0000ff">FROM</span> attendees<span style="color: #0000ff">WHERE</span> id <span style="color: #0000ff">IN</span> (              <span style="color: #0000ff">SELECT</span> attendeesid              <span style="color: #0000ff">FROM</span> AttendeesCodeCampYear              <span style="color: #0000ff">WHERE</span> codecampyearid = 6      )<span style="color: #0000ff">GROUP</span> <span style="color: #0000ff">BY</span>  <span style="color: #0000ff">LEFT</span> (userlastname, 1)O<span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> <span style="color: #0000ff">LEFT</span> (userlastname, 1)</pre>
<p></div>
<p>It’s pretty self explanatory.&#160; Our case is we have two tables that we track code camp attendees.&#160; One is the master list, and the other is a detail by year.&#160; (6 is this year)</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/10/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/10/image_thumb.png" width="344" height="198" /></a></p>
<p><span id="more-1600"></span></p>
<p>And, the results:</p>
<p>&gt; NULL&#160;&#160;&#160; 1</p>
<p>&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 6</p>
<p>&gt; .&#160;&#160;&#160;&#160;&#160;&#160; 1</p>
<p>&gt; @&#160;&#160;&#160;&#160;&#160;&#160; 1</p>
<p>&gt; _&#160;&#160;&#160;&#160;&#160;&#160; 18</p>
<p>&gt; A&#160;&#160;&#160;&#160;&#160;&#160; 319</p>
<p>&gt; B&#160;&#160;&#160;&#160;&#160;&#160; 488</p>
<p>&gt; C&#160;&#160;&#160;&#160;&#160;&#160; 543</p>
<p>&gt; Ç&#160;&#160;&#160;&#160;&#160;&#160; 2</p>
<p>&gt; D&#160;&#160;&#160;&#160;&#160;&#160; 313</p>
<p>&gt; E&#160;&#160;&#160;&#160;&#160;&#160; 84</p>
<p>&gt; F&#160;&#160;&#160;&#160;&#160;&#160; 169</p>
<p>&gt; g&#160;&#160;&#160;&#160;&#160;&#160; 368</p>
<p>&gt; H&#160;&#160;&#160;&#160;&#160;&#160; 340</p>
<p>&gt; I&#160;&#160;&#160;&#160;&#160;&#160; 49</p>
<p>&gt; J&#160;&#160;&#160;&#160;&#160;&#160; 190</p>
<p>&gt; K&#160;&#160;&#160;&#160;&#160;&#160; 474</p>
<p>&gt; L&#160;&#160;&#160;&#160;&#160;&#160; 460</p>
<p>&gt; M&#160;&#160;&#160;&#160;&#160;&#160; 592</p>
<p>&gt; N&#160;&#160;&#160;&#160;&#160;&#160; 255</p>
<p>&gt; O&#160;&#160;&#160;&#160;&#160;&#160; 79</p>
<p>&gt; P&#160;&#160;&#160;&#160;&#160;&#160; 427</p>
<p>&gt; Q&#160;&#160;&#160;&#160;&#160;&#160; 14</p>
<p>&gt; R&#160;&#160;&#160;&#160;&#160;&#160; 336</p>
<p>&gt; S&#160;&#160;&#160;&#160;&#160;&#160; 776</p>
<p>&gt; T&#160;&#160;&#160;&#160;&#160;&#160; 302</p>
<p>&gt; u&#160;&#160;&#160;&#160;&#160;&#160; 27</p>
<p>&gt; V&#160;&#160;&#160;&#160;&#160;&#160; 191</p>
<p>&gt; w&#160;&#160;&#160;&#160;&#160;&#160; 296</p>
<p>&gt; X&#160;&#160;&#160;&#160;&#160;&#160; 21</p>
<p>&gt; y&#160;&#160;&#160;&#160;&#160;&#160; 176</p>
<p>&gt; Z&#160;&#160;&#160;&#160;&#160;&#160; 100</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/10/04/tip-for-using-sqlserver-to-count-by-alpha-names-in-a-list/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My First Experience With SqlServer CE 4.0</title>
		<link>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-first-experience-with-sqlserver-ce-4-0</link>
		<comments>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 15:57:43 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[Sql Server CE]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/</guid>
		<description><![CDATA[I have heard all the hype about how great Sql Server CE 4.0 and that it is now standard with Visual Studio 2010 SP1.
&#160;

&#160;
I’ve got a small project (1 table) that I’d like to include in an asp.net website project so I decided to give it a try.&#160; For the most part, things have gone [...]]]></description>
			<content:encoded><![CDATA[<p>I have heard all the hype about how great <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">Sql Server CE 4.0</a> and that it is now standard with <a href="http://support.microsoft.com/kb/983509">Visual Studio 2010 SP1</a>.</p>
<p>&#160;</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image.png" width="592" height="185" /></a></p>
<p>&#160;</p>
<p>I’ve got a small project (1 table) that I’d like to include in an asp.net website project so I decided to give it a try.&#160; For the most part, things have gone smoothly, however I did have a couple hiccups I’d like to mention.&#160; One cost me <a href="http://www.gogoair.com/gogo/splash.do">$9</a> because I was doing this implementation on an airplane and immediately, I had a failed connection with a confusing error that I needed Bing to lookup&#160; (more details below).</p>
<p>&#160;</p>
<p>  <span id="more-1559"></span><br />
<h2>Method Names Changed</h2>
<p>&#160;</p>
<p>I have to wonder why Microsoft decided to change the names of the methods in ADO.NET.&#160; Seems to me that all the names should be the same whether I’m using Sql Server, Sql Server Express or Sql Server CE.&#160; My expectation was that the statement:</p>
<div id="codeSnippetWrapper">&#160;</div>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (<span style="color: #0000ff">var</span> connection = <span style="color: #0000ff">new</span> SqlConnection(testDataContext.ConnectionString)) {..</pre>
</div>
<div>&#160;</div>
<div>would work correctly, however, I get the very misleading (or at least unhelpful) error:</div>
<div>&#160;</div>
<h4><i>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 is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 &#8211; Error Locating Server/Instance Specified)</i></h4>
<div>&#160;</div>
<div>It turns out, you need to open the connection like this:</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (<span style="color: #0000ff">var</span> connection = <span style="color: #0000ff">new</span> SqlCeConnection(connectionString)) {...</pre>
<p></div>
<p>And things now work (my connection string is actually what I’ve pasted below).</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">&gt;</span>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ConnectionStringMxMessage&quot;</span> <span style="color: #ff0000">connectionString</span><span style="color: #0000ff">=&quot;Data Source=|DataDirectory|\MxMessageDb.sdf&quot;</span>       <span style="color: #ff0000">providerName</span><span style="color: #0000ff">=&quot;System.Data.SqlServerCe.4.0&quot;</span> <span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>Bottomline, all ado.net commands need the Ce in them.</p>
<p>&#160;</p>
<p>&#160;</p>
<h2>Getting Identity Column After Insert Fails</h2>
<p>&#160;</p>
<p>My expectation is that what has worked for a very long time in Sql Server for me should work in Sql Server CE.&#160; The most simple pattern of inserting a row and getting back the value of the identity column does not work the same.&#160; My original code looks like this (which fails):</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">using (var connection = new SqlCeConnection(testDataContext.ConnectionString))    {        connection.Open();        using (var sqlCeCommand =            new SqlCeCommand(                &quot;INSERT INTO message (Name, Subject, Header, Body, Footer) Values                     (@Name);SELECT @@IDENTITY&quot;,                connection))        {            sqlCeCommand.Parameters.Add(&quot;@Name&quot;, SqlDbType.NVarChar).Value = Name;            // problem, need to do separate select to get this to work            sqlCeCommand.Parameters.Add                (new SqlCeParameter(&quot;@IDENTITY&quot;, SqlDbType.Int)                                            {                                                Direction =                                                    ParameterDirection.Output                                            });

            using (var reader = sqlCeCommand.ExecuteReader())            {                while (reader.Read())                {                    message.Id = reader.IsDBNull(0) ? 0 :                       Convert.ToInt32(reader.GetDecimal(0));                }            }        }    }}</pre>
<p></div>
<p></div>
<p>To fix it, it seems that you can not send two sql commands on the same execution (separated by semicolon).&#160; That is, after the first command (without the SELECT @@IDENTITY) you need to do another SqlCeCommand as follows:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">using (var sqlCeCommand2 =    new SqlCeCommand(        &quot;SELECT @@IDENTITY&quot;,        connection)){    message.Id = Convert.ToInt32(sqlCeCommand2.ExecuteScalar());}</pre>
</div>
<h2>
<p>&#160;</p>
<p>Conclusions</p>
</h2>
<p>Well, things are working, but I have not done much and I’ve had a couple of stumbles.&#160; Hopefully I’m done with stumbling for now.</p>
<div>
  </div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Connecting To SqlServer From Web.Config Without a Password (Trusted Connection)</title>
		<link>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection</link>
		<comments>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 16:19:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/</guid>
		<description><![CDATA[I often forget that the simplest way (IMHO) to connect to a Microsoft SqlServer 2008 database is to use the web.config connection for making a Trusted connection.&#160; Basically, it keeps you from having to put a username and password in the web.config and also from having to keep track of different username and passwords on [...]]]></description>
			<content:encoded><![CDATA[<p>I often forget that the simplest way (IMHO) to connect to a <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer 2008</a> database is to use the <a href="http://msdn.microsoft.com/en-us/library/aa306178.aspx">web.config</a> connection for making a Trusted connection.&#160; Basically, it keeps you from having to put a username and password in the web.config and also from having to keep track of different username and passwords on different systems (like where you deploy to for example).&#160; The simplest connection string I can think of looks like this:</p>
<div id="codeSnippetWrapper">&#160;</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;add name=<span style="color: #006080">&quot;MyConnName&quot;</span> connectionString=<span style="color: #006080">&quot;Server=.;Database=mydbcatalogname;Trusted_Connection=True;&quot;</span>     providerName=<span style="color: #006080">&quot;System.Data.SqlClient&quot;</span> /&gt;</pre>
<p></div>
<p>Notice that I’m using the “.” as the server name.&#160; This allows me to reference the local system where my sqlserver lives. Not necessarily a best practice, but often is the case.</p>
<h3>Upside</h3>
<p>One big benefit is if you fall victim to a <a href="http://www.imperva.com/products/wsc_web-application_attacks.html">disk scraping attack</a>, or someone gets a hold of your source (maybe from version control?), you don’t give up your passwords.</p>
<h3>Downside</h3>
<p>If you SqlSever is not on the system system as your web project or application, then this become more tricky because of the cross system authentication issues.&#160; If you have active directory installed on both systems, then this works also.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SqlAzure and a Best Practices way to deal with the Required Retries on Connections</title>
		<link>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sqlazure-connection-retry-problem-using-best-practices</link>
		<comments>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 22:24:44 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[SqlAzure]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[Web.Config]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/</guid>
		<description><![CDATA[Introduction
If you’ve started using SqlAzure for your SqlServer with your Azure application, you’ve probably discovered that you get a reasonable number of connection failures.&#160; The advice from the Azure team is add retry logic to all your connections to SqlAzure. There is a long discussion posted by the Azure team here.
The key paragraph states the [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>If you’ve started using <a href="http://msdn.microsoft.com/en-us/library/ee336279.aspx">SqlAzure</a> for your <a href="http://www.microsoft.com/sqlserver/2008/en/us/r2.aspx">SqlServer</a> with your Azure application, you’ve probably discovered that you get a reasonable number of <a href="http://msdn.microsoft.com/en-us/library/aa175395(v=sql.80).aspx">connection</a> failures.&#160; The advice from the Azure team is add retry logic to all your connections to SqlAzure. There is a long discussion posted by the Azure team <a href="http://blogs.msdn.com/b/bartr/archive/2010/06/18/sql-azure-connection-retry.aspx?utm_source=feedburner&amp;utm_medium=twitter&amp;utm_campaign=Feed%3A+Microsoft%2FMSDN-Blogs+(MSDN+Blogs)">here</a>.</p>
<p>The key paragraph states the problem as follows:</p>
<blockquote><p><strong>The Problem       <br /></strong>One of the things that SQL Azure does to deliver high availability is it sometimes closes <a href="http://msdn.microsoft.com/en-us/library/ee336245.aspx">connections</a>. SQL Azure does some pretty cool stuff under the covers to minimize the impact, but this is a key difference in SQL Azure development vs. SQL Server development.</p>
</blockquote>
<p>Basically, what this means is that you must be able to deal with connections failing when you call SqlAzure.&#160; Something that all of probably should have been doing forever, but because most of the time SqlServer is running on your local LAN and the likelihood if a connection failing was next to zero unless something else was going terribly wrong.&#160; Certainly not something we had to do on regular basis.&#160; To emphasize that even more, most of the controls built into asp.net that open connections to sqlserver don’t even do this and that’s from Microsoft itself.</p>
<p>The solution proposed in the thread mentioned above basically has you add tons of code to everyplace you access a connection object.&#160; Personally, I don’t like that because I have hundreds if not thousands of places I open connections and inserting tens of thousands of lines of extra new untested code is a little scary.</p>
<p>So, what to do?</p>
<p>Fortunately, another team at Microsoft, known as the <a href="http://blogs.msdn.com/b/appfabriccat">Windows Server AppFabric Customer Advisory Team</a> published a general purpose solution using Extension Methods and some darn clever coding wrote a <a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx">great article and published code</a> including <a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx">azure examples</a> that solves this problem very elegantly without requiring a lot of changes to your existing code base.</p>
<p>In this article I plan on giving an example and publishing a sample project that uses this code with SqlAzure to solve the connection retry problem.&#160; My goal here is not to simply restate what they published but to simply have a very simple concrete example of using their library.</p>
<p>  <span id="more-1429"></span><br />
<h2>Design Goal</h2>
<p>We have two goals.</p>
<ol>
<li>
<div align="left">Change as little code as possible</div>
</li>
<li>
<div align="left">Log Connection Errors when they happen With Locations</div>
</li>
<li>
<div align="left">Make sure not to trap errors that are NOT connection related such as bad column names</div>
</li>
</ol>
<p align="left">&#160;</p>
<h2 align="left">Incorrect Code</h2>
<p align="left">So, this is what the original code looks like that will fail because it does not have connection retry logic:</p>
<p align="left">&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> UsersIdFromUserNameNoConnectionRetry(<span style="color: #0000ff">string</span> userName){    var retUsersId = 0;    <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> sql =        <span style="color: #006080">@&quot;SELECT Id FROM Users            WHERE Username = @Username&quot;</span>;

    <span style="color: #0000ff">using</span> (var sqlConnection = <span style="color: #0000ff">new</span> SqlConnection(            ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].            ConnectionString))    {        sqlConnection.Open();        <span style="color: #0000ff">using</span> (var sqlCommand = <span style="color: #0000ff">new</span> SqlCommand(sql, sqlConnection))        {            sqlCommand.Parameters.Add(<span style="color: #006080">&quot;@Username&quot;</span>, SqlDbType.NVarChar).Value = userName;            <span style="color: #0000ff">using</span> (var reader = sqlCommand.ExecuteReader())            {                <span style="color: #0000ff">while</span> (reader.Read())                {                    retUsersId = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);                }            }        }    }    <span style="color: #0000ff">return</span> retUsersId;}</pre>
<p></div>
<p align="left">So, if there is a connection, an exception will get thrown and will need to be caught, but then the method will not have done it’s job.</p>
<p align="left">&#160;</p>
<h2 align="left">Correct Code With Retries</h2>
<p align="left">So, now take a look at the revised code after the library is setup and used.&#160; The setup is non-trivial, but you just have to do that once and then you can simply fix all your other code with very few changes.&#160; Below is the new code with connection retry logic built in.</p>
<p align="left">&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> UsersIdFromUserName(<span style="color: #0000ff">string</span> userName){    var retUsersId = 0;    <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> sql =        <span style="color: #006080">@&quot;SELECT Id FROM Users            WHERE Username = @Username&quot;</span>;

    <span style="color: #0000ff">using</span> (var sqlConnection =        <span style="color: #0000ff">new</span> ReliableSqlConnection(            ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].            ConnectionString,            <span style="color: #0000ff">new</span> RetryUtils(<span style="color: #006080">&quot;&quot;</span>, <span style="color: #006080">&quot;UsersIdFromUserName&quot;</span>).GetRetryPolicy()))    {        sqlConnection.Open();        <span style="color: #0000ff">using</span> (var sqlCommand = <span style="color: #0000ff">new</span> SqlCommand(sql, sqlConnection.Current))        {            sqlCommand.Parameters.Add(<span style="color: #006080">&quot;@Username&quot;</span>, SqlDbType.NVarChar).Value = userName;            <span style="color: #0000ff">using</span> (var reader = sqlCommand.ExecuteReader())            {                <span style="color: #0000ff">while</span> (reader.Read())                {                    retUsersId = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);                }            }        }    }    <span style="color: #0000ff">return</span> retUsersId;}</pre>
</div>
<div>&#160;</div>
<div>There are basically two changes.&#160; </div>
<div>&#160;</div>
<ol>
<li>The first is instead of create an SqlConnection(…) we are creating a ReliableSqlConnection(…).&#160; The ReliableSqlConnection takes an extra parameter which basically wraps the retry logic used, as well as labelling this connection so when it fails, it gets logged.&#160; In the log, there will be the comment “UsersIdFromUserName” so we know what method threw the retry.</li>
<li>The second is slight change we when we create the SqlCommand, we have to add the property .Current to it so we know we are talking about the currently executing connection.&#160; There may be a default way to handle this but I could not figure it out.</li>
</ol>
<div>That’s it!&#160; you are new connection safe for retrying failed connections.</div>
<div>&#160;</div>
<h2>The Setup Pieces</h2>
<div>&#160;</div>
<div>First, download the library from the article mention above which can be found here in <a href="http://code.msdn.microsoft.com/">Microsoft’s Code Gallery</a></div>
<div>&#160;</div>
<div><a title="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007" href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007">http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007</a></div>
<div>&#160;</div>
<p>The project has all kinds of stuff in it that build quite nicely, run and test under vs2010.&#160; All I’m interested in is the ado.net piece and the retry logic around that.&#160; I actually used the 1.2 version, however I now see there is a 1.3 version with some improvements.&#160; I would post my project but I don’t want to post it with old code so I’ll just tell you the steps I went through so you can do the same.</p>
<h3>Build the class library</h3>
<p>Compile the project and make sure you have the dll from the library lincluded in your actual visual studio project.&#160; The library you want is Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/SqlAzure-and-a-Best-Practices-way-to-dea_E1CC/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/SqlAzure-and-a-Best-Practices-way-to-dea_E1CC/image_thumb.png" width="347" height="243" /></a></p>
<p>&#160;</p>
<h3>Update Your Web.config</h3>
<p>Add the config section below to your web.config file.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;RetryPolicyConfiguration&quot;</span>          <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.Configuration.RetryPolicyConfigurationSettings,            Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling&quot;</span> <span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">RetryPolicyConfiguration</span> <span style="color: #ff0000">defaultPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">defaultSqlConnectionPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span>          <span style="color: #ff0000">defaultSqlCommandPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">defaultStoragePolicy</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span>          <span style="color: #ff0000">defaultCommunicationPolicy</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">retryInterval</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">retryInterval</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #ff0000">retryIncrement</span><span style="color: #0000ff">=&quot;50&quot;</span> <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ExponentialIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">minBackoff</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #ff0000">maxBackoff</span><span style="color: #0000ff">=&quot;1000&quot;</span> <span style="color: #ff0000">deltaBackoff</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">RetryPolicyConfiguration</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>This defines a new section in your web.config, then implements it with several different retry policies include a default one which seems quite reasonable to me.</p>
<p>If you remember, in the implementation section above, we used a public class called RetryUtils.&#160; This class is actually one I invented as a convenience class to minimize the code I have to update on each use of the ReliableConnection Object.&#160; Just to refresh your memory, the implementation is this:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (var sqlConnection =                <span style="color: #0000ff">new</span> ReliableSqlConnection(                    ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].                    ConnectionString,                    <span style="color: #0000ff">new</span> RetryUtils(<span style="color: #006080">&quot;&quot;</span>, <span style="color: #006080">&quot;UsersIdFromUserName&quot;</span>).GetRetryPolicy()))</pre>
<p></div>
<p>The actual code fo rthe class RetryUtils is below here.&#160; You’ll have to stick this someplace in your project.</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">namespace</span> Utils{

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RetryUtils    {        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Username { get; set; }        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> CallersName { get; set; }

        <span style="color: #0000ff">public</span> RetryUtils(<span style="color: #0000ff">string</span> username, <span style="color: #0000ff">string</span> callersName)        {            Username = username;            CallersName = callersName;        }

        <span style="color: #0000ff">public</span> RetryUtils()        {            Username = <span style="color: #0000ff">string</span>.Empty;            CallersName = <span style="color: #0000ff">string</span>.Empty;        }

        <span style="color: #0000ff">public</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt; GetRetryPolicy()        {            var retryPolicy = <span style="color: #0000ff">new</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt;                 (RetryPolicy.DefaultClientRetryCount, RetryPolicy.DefaultMinBackoff,                  RetryPolicy.DefaultMaxBackoff,                  RetryPolicy.DefaultClientBackoff);

            retryPolicy.RetryOccurred += RetryPolicyRetryOccurred;

            <span style="color: #0000ff">return</span> retryPolicy;        }

        <span style="color: #0000ff">void</span> RetryPolicyRetryOccurred(<span style="color: #0000ff">int</span> currentRetryCount, Exception lastException, TimeSpan delay)        {            GeneralUtils.GetLog4NetAllDataContext().AddLog4NetAll(<span style="color: #0000ff">new</span> Log4NetAll                                                    {                                                        Date = DateTime.UtcNow,                                                        EllapsedTime = 0,                                                        ExceptionStackTrace = lastException.StackTrace,                                                        Message = <span style="color: #006080">&quot;RetryCount: &quot;</span> + currentRetryCount + <span style="color: #006080">&quot; delay: &quot;</span> + delay.Seconds,                                                        ExceptionMessage = lastException.Message,                                                        Logger = <span style="color: #006080">&quot;&quot;</span>,                                                        Level = <span style="color: #006080">&quot;Error&quot;</span>,                                                        UserName = Username,                                                        PartitionKey = Username,                                                        RowKey = Guid.NewGuid().ToString()                                                    });        }           }}</pre>
</div>
<div>This code actually has the nice callback delegate that does the logging when a retry actually occurs.&#160; I’m not including my implementation of GeneralUtils.GetLog4NetAllDataContext().AddLog4NetAll, but you can pretty much guess what it does.&#160; It simply logs the retry with all the details of what happened.&#160; My implementation sticks this in an Azure Table, but that’s really for another post.</div>
<div>&#160;</div>
<h2>Non Connection Related Errors</h2>
<div>&#160;</div>
<div>Remember, our second design criteria is that we should only fail on errors that are connection related and not things like data column not found.&#160; With no additional work, this library takes care of this for us.&#160; Actually, in the release notes for the 1.3 release (which I have not used yet) say they have improved that feature by adding additional codes not to fail on.&#160; That is, the last thing you want is your code spending 5 minutes retrying on a problem you’d just like reported immediately. </div>
<div>&#160;</div>
<div>Keep in mind that the library we are using here is a general purpose retry library not designed just for use with ado.net.&#160; The team has provided us with examples using LINQ2SQL, EntityFramework and other technologies.&#160; I spent&#160; a little time reading about using those other technologies but did not get far enough to blog about it.&#160; My current SqlAzure implementation uses 100% ado.net because performance is critical to me and neither EF or LINQ2SQL are quite up to my task yet.</div>
<div>&#160;</div>
<h2>Conclusions</h2>
<div>&#160;</div>
<div>So basically, that’s it!&#160; You know have the tools to implement very nice retry logic in your ado.net code so Azure will not fail on “normal” connection failures.&#160; I suggest that if you are using SqlAzure, you implement this as soon as possible so your code will be solid going forward.</div>
<div>&#160;</div>
<div>Thanks for reading!</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Writing A Transact SQL (TSQL) Procedure For SQL Server 2008 To Delete Rows From Table Safely</title>
		<link>http://peterkellner.net/2010/04/29/sqlserver2008-tsql-storedproc-delete-rows-in-groups-safely/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sqlserver2008-tsql-storedproc-delete-rows-in-groups-safely</link>
		<comments>http://peterkellner.net/2010/04/29/sqlserver2008-tsql-storedproc-delete-rows-in-groups-safely/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 23:54:21 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[Transaction]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/04/29/sqlserver2008-tsql-storedproc-delete-rows-in-groups-safely/</guid>
		<description><![CDATA[In this post, we will show and explain a small TSQL Sql Server 2008 procedure that deletes all rows in a table that are older than some specified date.&#160; That is, say the table has 10,000,000 rows in it the accumulated over the past 2 years.&#160; 
Say you want to delete all but the last [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, we will show and explain a small <a href="http://msdn.microsoft.com/en-us/library/ms189826(SQL.90).aspx">TSQL</a> <a href="http://www.microsoft.com/sqlserver/2008/en/us/">Sql Server 2008</a> procedure that deletes all rows in a table that are older than some specified date.&#160; That is, say the table has 10,000,000 rows in it the accumulated over the past 2 years.&#160; </p>
<p>Say you want to delete all but the last 30 days of activity.&#160; If you just simply say <a href="http://msdn.microsoft.com/en-us/library/ms189835.aspx">DELETE</a> FROM table WHERE id&gt;10000, you will cause this to happen in one transaction and likely, you will get an error.&#160; That’s the best case.&#160; The worst case is your system tries to do this, eventually consumes all the resources in your computer and crashes your server.</p>
<p> <span id="more-1285"></span>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> dbo.DeleteRowsInGroupsBeforeNdaysLog4NetAll@NoOfRowsToDelete <span style="color: #0000ff">int</span>,@DaysBeforeTodayToDelete <span style="color: #0000ff">int</span><span style="color: #0000ff">AS</span><span style="color: #0000ff">BEGIN</span>

  <span style="color: #0000ff">DECLARE</span> @DateToDeleteBefore <span style="color: #0000ff">date</span>    <span style="color: #008000">-- Number Of Days To Delete Records From</span>  <span style="color: #0000ff">DECLARE</span> @DateToday datetime         <span style="color: #008000">-- To Hold Todays Date</span>  <span style="color: #0000ff">DECLARE</span> @PrintMessage <span style="color: #0000ff">varchar</span>(256)  <span style="color: #008000">-- To Hold Print Message        </span>  <span style="color: #0000ff">DECLARE</span> @CurrentRowCount <span style="color: #0000ff">int</span>        <span style="color: #008000">-- Scratch Var For Counting Rows</span>

  <span style="color: #0000ff">SET</span> @DateToday = GetDate()

  <span style="color: #0000ff">SELECT</span> @CurrentRowCount =         (           <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">COUNT</span>(*)           <span style="color: #0000ff">FROM</span> dbo.Log4NetAll           <span style="color: #0000ff">WHERE</span> <span style="color: #0000ff">Date</span> &lt;(@DateToday - @DaysBeforeTodayToDelete)         ) 

  <span style="color: #0000ff">WHILE</span> (@CurrentRowCount &gt; 0) <span style="color: #0000ff">BEGIN</span>      <span style="color: #0000ff">DELETE</span> <span style="color: #0000ff">TOP</span> (@NoOfRowsToDelete)      <span style="color: #0000ff">FROM</span> dbo.Log4NetAll        <span style="color: #0000ff">WHERE</span> Id <span style="color: #0000ff">IN</span> (        <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">TOP</span> (@NoOfRowsToDelete) Id         <span style="color: #0000ff">FROM</span> Log4NetAll        <span style="color: #0000ff">WHERE</span> <span style="color: #0000ff">Date</span> &lt; (@DateToday - @DaysBeforeTodayToDelete)        <span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> Id <span style="color: #0000ff">ASC</span>)

       <span style="color: #008000">-- Count the records again</span>       <span style="color: #0000ff">SELECT</span> @CurrentRowCount =         (           <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">COUNT</span>(*)           <span style="color: #0000ff">FROM</span> dbo.Log4NetAll           <span style="color: #0000ff">WHERE</span> <span style="color: #0000ff">Date</span> &lt;(@DateToday - @DaysBeforeTodayToDelete)         )        <span style="color: #0000ff">SET</span> @PrintMessage = N<span style="color: #006080">'Deleting This Many Rows: '</span>                            + (<span style="color: #0000ff">CAST</span>(@CurrentRowCount <span style="color: #0000ff">AS</span> nvarchar(10)));       <span style="color: #0000ff">PRINT</span> @PrintMessage;  <span style="color: #0000ff">END</span>  END</pre>
<p></div>
<div>* Inspired by a <a href="http://www.sqlservercurry.com/2008/04/how-to-delete-records-from-large-table.html">blog post by Suprotim Agarwal</a> </div>
<div>&#160;</div>
<div id="codeSnippetWrapper">Basically, what is happening in the above code is first, we are testing to see if there are any records that meet our criteria to delete.&#160; That is, records older than a certain date.&#160; Next, we have a WHILE loop that continue until there are no more records that meet the criteria.&#160; The <a href="http://msdn.microsoft.com/en-us/library/ms189835.aspx">DELETE SQL command</a> uses TOP, which is very handy because it will delete up to that many.&#160; That way, you don’t have to worry about deleting the last few records with any special case code.</div>
<div>&#160;</div>
<div>The only thing a little tricky that I did was to actually delete the records with <a href="http://msdn.microsoft.com/en-us/library/ms189575.aspx">Subquery</a> that forces a sort of the records before deleting.&#160; That is, by asking for Id IN (Records sorted ascending), I’m forcing my TOP command to delete the oldest records first.&#160; This may not be necessary if your method runs to completion, but if you interrupt it, it might be convenient for the oldest records to be deleted first.</div>
<div>
  </div>
<p>Then, do Execute the Procedure, you would call it as follows assuming you wanted to delete the code in batches.</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">DECLARE</span> @NoOfRowsToDelete <span style="color: #0000ff">int</span>;<span style="color: #0000ff">DECLARE</span> @DaysBeforeTodayToDelete <span style="color: #0000ff">int</span>;

<span style="color: #0000ff">SET</span> @NoOfRowsToDelete = 100;<span style="color: #0000ff">SET</span> @DaysBeforeTodayToDelete = 30;

<span style="color: #0000ff">EXEC</span> [dbo].[DeleteRowsInGroupsBeforeNdaysLog4NetAll]   @NoOfRowsToDelete, @DaysBeforeTodayToDelete ;</pre>
<p></div>
<p>The output of calling this might be:</p>
<p>Query execution was canceled by user request.<br />
  <br />Deleting This Many Rows: 19199 </p>
<p>Deleting This Many Rows: 19099 </p>
<p>Deleting This Many Rows: 18999 </p>
<p>Deleting This Many Rows: 18899 </p>
<p>Deleting This Many Rows: 18799 </p>
<p>Deleting This Many Rows: 18699 </p>
<p>Deleting This Many Rows: 18599… (All the way until 0)</p>
<p>&#160;</p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/04/29/sqlserver2008-tsql-storedproc-delete-rows-in-groups-safely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bravo for ORCSWeb! On so many fronts</title>
		<link>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=orcsweb-hosting-company-awesome-review</link>
		<comments>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 19:59:07 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Code Camp Web Site Series]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/</guid>
		<description><![CDATA[Many of you know of ORCSWeb either by reputation, or by way of Scott Forsyth, one of my ASP.NET MVP brothers.&#160; In case you don’t, they are a managed hosting solutions company specializing in Microsoft technologies.&#160; I’ve used their basic services for quite a while and have always been very happy.&#160; It has always seemed [...]]]></description>
			<content:encoded><![CDATA[<p>Many of you know of <a href="http://www.orcsweb.com/">ORCSWeb</a> either by reputation, or by way of <a href="http://weblogs.asp.net/owscott/default.aspx">Scott Forsyth</a>, one of my ASP.NET MVP brothers.&#160; In case you don’t, they are a managed hosting solutions company specializing in Microsoft technologies.&#160; I’ve used their basic services for quite a while and have always been very happy.&#160; It has always seemed that anytime I’ve called them (and it always seems like the middle of the night) one of their tech support staff is always available to help me, and go the extra mile if necessary.</p>
<p>The company I’m now working at is small and we don’t have a lot of resources to maintain hardware and do operating system type support.&#160; We do have a high load requirement so we need a very robust supported solution.&#160; Before this, I’d always been in the under $50 per month type plan with ORCSWeb, but I decided I needed more servers and a higher level of support.&#160; I really did not know what level of support to expect when signing up for the managed servers but decided to go for it anyway.</p>
<p>All&#160; can say is <strong>WOW!!!</strong>&#160; I am over the top impressed. </p>
<p> <span id="more-337"></span>
<p>We currently have 3 virtual servers hosted at ORCSWeb.&#160; One, we use as a development server, and the other two are in a webfarm configuration.&#160; I’ve always believed that when you go into production with a web site it’s critical you start with 2 servers in a webfarm.&#160; it’s really easy to go from 2 to 10, but can be very painful to go from 1 to 2.&#160;&#160; That’s a topic for another post, but suffice it to say, 2 is the minimum.</p>
<p>So, why am I so impressed?&#160; First, the support team they assigned to me is totally awesome.&#160; They all are focussed and competent which is a total relief compared with most hosting companies I’ve dealt with.&#160; Other companies always have good people, but it seems to be the bad ones that really give me cause to remember.&#160; Second, because I paid extra for the full managed support options on our three servers, I’ve been able to ask the things like the following.&#160; Almost all of them I could do myself, but I’m swamped with my technology role in the new company and really appreciate being able to hand stuff like this off.</p>
<ul>
<li>I’ve pointed my MX record at my .149 server.&#160; Could you please set up email and create the following 7 accounts. </li>
<li>Please Setup a secure ftp server at the following address with the following username and password (and make sure the user is locked down to the root) </li>
<li>Setup DFS Replication between these two directories on .148 and .149 </li>
<li>Create a RoboCopy script that copies files from my dev server to the .149 mirrored directory </li>
<li>Please set up web statistics for me on <a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a> </li>
<li>Please figure out why SqlServer 2008 is not letting me access catalog MyStuff1 from user 3p1 and fix </li>
<li>Please make a replicate of website MyWeb1.com including the sqlserver catalog’s and put it on MyWeb2.com on server .149 </li>
<li>Please replace the sqlserver catalog MyStuff3 on server .149 with the bak file I uploaded to my ftp server </li>
<li>I could go on and on, but I think you are getting the idea. </li>
<li>Always with a smile, 24&#215;7, what else can I say. </li>
</ul>
<p>By the way, if you want to see one of my sites hosted there, go to <a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a></p>
<p>Thank you <a href="http://www.orcsweb.com/">ORCSWeb</a> for making things a lot easier for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Load Balancing IIS Web Farm with EC2</title>
		<link>http://peterkellner.net/2009/04/20/web-farm-ec2-amazon-steveevans-cloud-computing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=web-farm-ec2-amazon-steveevans-cloud-computing</link>
		<comments>http://peterkellner.net/2009/04/20/web-farm-ec2-amazon-steveevans-cloud-computing/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 04:08:36 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[WebFarm]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/04/20/web-farm-ec2-amazon-steveevans-cloud-computing/</guid>
		<description><![CDATA[&#160;
We’ve been looking to find the best Cloud based host to put our soon to be virally growing web site up on.&#160; Our requirements are it must run IIS7 and use Sql Server 2008 as it’s database. We have lots of wants (like Service Broker, Replication, etc.) but primarily we want the web tier to [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>We’ve been looking to find the best <a href="http://www.cloudcamp.com/">Cloud based host</a> to put our soon to be virally growing web site up on.&#160; Our requirements are it must run <a href="http://www.iis.net/">IIS7</a> and use <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">Sql Server 2008</a> as it’s database. We have lots of wants (like Service Broker, Replication, etc.) but primarily we want the web tier to scale easily.&#160; After doing research and testing, we got frustrated with our options at <a href="http://aws.amazon.com/ec2/">Amazon’s EC2</a>.&#160; We emailed their support (with our paid support contract) and were basically told we should go do our own Windows research to find out what works best.</p>
<p>At any rate, I emailed <a href="http://serktools.com/about-us/">Steve Evan’s</a> who is a frequent speaker at conferences and also an expert consultant on all things Windows and IT related and asked for some advice.&#160; He told me that he had been asked that question often recently by others so he would do some research and get back to me.&#160; He did one step better.&#160; He wrote a blog post describing the ups and downs of the different cloud providers including Amazon’s EC2.&#160; I respect Steve’s opinion a lot and rather than try and paraphrase it, I’ll just link to his post.</p>
<p>Here it is:&#160; <a title="http://serktools.com/2009/04/20/load-balancing-iis-web-farm-on-amazon-ec2/" href="http://serktools.com/2009/04/20/load-balancing-iis-web-farm-on-amazon-ec2/">http://serktools.com/2009/04/20/load-balancing-iis-web-farm-on-amazon-ec2/</a></p>
<p>Good luck and feel free to post comments here if you’ve got opinions on Cloud Hosting of IIS and Sql Server 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/04/20/web-farm-ec2-amazon-steveevans-cloud-computing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Great New Book on Business Intelligence Solutions and Sql Server 2008 by Lynn Langit</title>
		<link>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=businessintelligencebookreviewlynnlangit</link>
		<comments>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 00:42:49 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=260</guid>
		<description><![CDATA[I’m sure many of you know Lynn Langit.&#160; Her role at Microsoft has been a Developer Evangelist of many of the business software offerings from Microsoft including Sharepoint and SqlServer and it’s many offerings.&#160; She’s always been a wealth of great information about those products and it’s great to see she’s got a book out [...]]]></description>
			<content:encoded><![CDATA[<p>I’m sure many of you know <a href="http://blogs.msdn.com/socaldevgal/about.aspx">Lynn Langit</a>.&#160; Her role at Microsoft has been a Developer Evangelist of many of the business software offerings from Microsoft including <a href="http://www.microsoft.com/Sharepoint/default.mspx">Sharepoint</a> and <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">SqlServer</a> and it’s many offerings.&#160; She’s always been a wealth of great information about those products and it’s great to see she’s got a book out about one of her favorite topics, Business Intelligence.</p>
<p>So far, I’ve read the first four chapters and have skimmed the rest.&#160; I am so far very impressed with both how well it’s written and the depth of topics the book covers.&#160; As I read more, I’ll come back and update this post.&#160; I have no doubts I will get a lot out of this book, as I’m sure practically anyone else who buys it will also.</p>
<p> <span id="more-260"></span>
<p>If you want to read more of Lynn’s stuff, check out her blog at <a title="http://blogs.msdn.com/socaldevgal/" href="http://blogs.msdn.com/socaldevgal/">http://blogs.msdn.com/socaldevgal/</a></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:762c08a5-66d8-456c-b756-04bdd0f0bf6b" class="wlWriterSmartContent">
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<p><a title="Smart Business Intelligence Solutions with Microsoft® SQL Server® 2008 (PRO-Developer): Lynn Langit, Kevin S. Goff, Davide Mauri, Sahil Malik, John Welch: Books" href="http://www.amazon.com/exec/obidos/ASIN/0735625808/petkelsblo-20"><img style="float: left" border="0" align="left" src="http://images.amazon.com/images/P/0735625808.01.MZZZZZZZ.jpg" />Smart Business Intelligence Solutions with Microsoft® SQL Server® 2008 (PRO-Developer): Lynn Langit, Kevin S. Goff, Davide Mauri, Sahil Malik, John Welch: Books</a></p>
</td>
</tr>
</tbody>
</table></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Experience with Visual Studio 2008 Database Edition, I love it!!!</title>
		<link>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visual-studio-database-edition-review-sqlserver2008</link>
		<comments>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:06:11 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/</guid>
		<description><![CDATA[As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what Microsoft Visual Studio Team has put together with the Database Edition and can be seen for sale here as the 
Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what <a href="http://msdn.microsoft.com/en-us/vsts2008/products/bb933747.aspx">Microsoft Visual Studio Team</a> has put together with the <a href="http://blogs.msdn.com/gertd/archive/2007/11/21/visual-studio-team-system-2008-database-edition.aspx">Database Edition</a> and can be seen for sale here as the </p>
<p><a href="http://click.linksynergy.com/fs-bin/click?id=cLhVEJVzoSE&#038;offerid=166833.737&#038;type=2&#038;subid=0">Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from Microsoft</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=cLhVEJVzoSE&#038;bids=166833.737&#038;type=2&#038;subid=0" ></p>
<p> I&#8217;ll first try and explain in a nutshell what it is.&#160; Then I&#8217;ll go through an example of creating a Visual Studio Database Project out of a site I&#8217;ve been working on to show the steps.&#160; Finally, I&#8217;ll give a short summary reliving the experience and giving you some other pointers that may help you get through the experience.</p>
<h3>What is VS2008 Database Edition?</h3>
<p>Basically, what VS2008 does is to first process your existing schema into hundreds (maybe thousands) of little files.&#160; That is, each file is one database thing. That thing might be a table definition, a stored procedure, a trigger, a constraint, a foreign key, etc.&#160; The beauty of this is that now, each thing can be tracked separately.&#160; Say for example, you want to update just one table and someone else on your team wants to update another table in the same schema.&#160; Since the files are now separate files, it&#8217;s no problem.&#160; When you grab the latest changes from source control, you will get your friends changes and he will get yours.&#160; Very very clean!</p>
<div id='extendedEntryBreak' name='extendedEntryBreak'></div>
<p>Also, it has a very powerful comparison engine.&#160; Say you update your data outside of this project.&#160; VS2008 Database Edition will compare your definitions in all these little files with either a sql script you generate, or it will connect to an external database and compare to that.&#160; Me personally, I like to use a tool called <a href="http://www.sqlmanager.net/en/products/studio/mssql">SqlManager</a> to manage my data.&#160; I can continue to do that, then when I&#8217;ve made my changes, I can simply connect VS2008 Database Edition to my updated development database and it will automatically figure out the changes.</p>
<p>So, you may ask, what version do I need to run this of Visual Studio?&#160; The answer is in this link:&#160; <a title="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx" href="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx">http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx</a></p>
<h3>Here We Go, Let&#8217;s do an Example</h3>
<p>So, first, I will open my existing solution which has a web project in it, a data access project as well as other projects.&#160; Then, I create the new Database solution by saying File/Open/New Project/Database Project.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb.png" width="395" height="208" /></a></p>
<p>Then, we follow the wizard&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_3.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_3.png" width="244" height="182" /></a></p>
<p>Taking defaults&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_4.png" width="244" height="182" /></a></p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_5.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_5.png" width="244" height="182" /></a></p>
<p>Now, I choose my schema.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_6.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_6.png" width="244" height="182" /></a></p>
<p>Press Start&#8230;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_7.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_7.png" width="244" height="182" /></a></p>
<p>Once you&#8217;ve done that, you&#8217;ll now have your schema spread out across your project in little files.&#160; Below is what the &quot;file based&quot; view of your schema looks like.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_8.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_8.png" width="412" height="295" /></a></p>
<p>Notice that the file we are looking at also includes comments for both the table and the columns using the standard extended property documentation format as follows:</p>
<pre class="csharpcode"><span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>,
@<span class="kwrd">value</span> = N<span class="str">'tracks all changes from each camp

title;link;guid;pubDate;category;description'</span>, @level0type = N<span class="str">'SCHEMA'</span>,
@level0name = N<span class="str">'dbo'</span>, @level1type = N<span class="str">'TABLE'</span>,
@level1name = N<span class="str">'CampFeed'</span>;

<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>,
@<span class="kwrd">value</span> = N<span class="str">'if true, this is the main news feed from the site.
there should only be one main news feed from any site.  this would
not be feeds like twitter'</span>, @level0type = N<span class="str">'SCHEMA'</span>,
@level0name = N<span class="str">'dbo'</span>,
@level1type = N<span class="str">'TABLE'</span>, @level1name = N<span class="str">'CampFeed'</span>,
@level2type = N<span class="str">'COLUMN'</span>, @level2name = N<span class="str">'PrimaryFeed'</span>;</pre>
<pre class="csharpcode">&#160;</pre>
<pre class="csharpcode">Now, when you actually build the project as follows:</pre>
<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_9.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_9.png" width="242" height="244" /></a> </pre>
<p>it will generate the full script combining all the files back into one again. Here is where it puts it:</p>
<pre class="csharpcode">&#160;</pre>
<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_10.png" width="414" height="332" /></a> </pre>
<pre class="csharpcode">&#160;</pre>
<p>So, that&#8217;s about it for now. I haven&#8217;t gone into any of the ways to compare and update your schema based on external changes, but we can leave that for another post.</p>
<p>To see a great video by <a href="http://blog.hundhausen.com/">Richard Hundhausen</a>, President of <a title="http://www.accentient.com/" href="http://www.accentient.com/">Accentient</a>, a <a href="http://msdn.microsoft.com/en-us/vsts2008/aa718934.aspx">Team Systems</a> Consulting company, go to this link:&#160; <a title="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx" href="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx">http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx</a></p>
<p>Also, if you are using Sql Server 2008, make sure you install visual studio 2008 sp1, then go to this link and install the download:&#160; <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en</a></p>
<h3>Conclusions</h3>
<p>From what I can tell, this Visual Studio Database Edition will be a huge help in building database schema&#8217;s and database programs (sp&#8217;s, triggers,etc.) in a collaborative environment.&#160;&#160; If you have the license to use this, I strongly recommend it.&#160; It is definitely going to be part of my tool kit for now on.&#160; Even if I&#8217;m the only author in the project.</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>LINQPad is Totally Awesome at Testing and Writing LINQ Queries</title>
		<link>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linqpad-sqlserver-linq-interpreter-nutshell</link>
		<comments>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 02:25:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/</guid>
		<description><![CDATA[http://www.linqpad.net/ &#8211; Use with Microsoft .Net for building Query type expressions with LINQ
I&#8217;m not a wizard at writing LINQ expressions so I often find myself in Google looking for something similar to what I want, then I put it into my application and run it. This has worked pretty well, but it takes a couple [...]]]></description>
			<content:encoded><![CDATA[<p><a title="http://www.linqpad.net/" href="http://www.linqpad.net/">http://www.linqpad.net/</a> &#8211; Use with Microsoft .Net for building Query type expressions with LINQ</p>
<p>I&#8217;m not a wizard at writing <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ</a> expressions so I often find myself in <a href="http://google.com">Google</a> looking for something similar to what I want, then I put it into my application and run it. This has worked pretty well, but it takes a couple iterations to get it right. It occured to me that someone probably has written a LINQ interpreter so I just guessed the name, <a href="http://www.linqpad.net/">LINQPad</a>, typed it into search, and I find the authors of the book C# 3.0 in a nutshell, <a href="http://www.technosis.com.au/Training.aspx">Joseph Albahari</a> and <a href="http://www.oreillynet.com/pub/au/465">Ben Albahari</a>, (which I like a lot) have written it.</p>
<p> <span id="more-162"></span>
<p>I download it (it&#8217;s an exe file), run it (OK, I trust you guys somehow), and presto, I get a very nice interface that not only has tons of examples built into it with a nice tree view, but lets me make a connection to my database and run LINQ queries against it. It even cancels them when you create one that will run forever (very nice guys!).</p>
<p>So, the query I was going after is I have a huge list of cities that includes states. From that, I just want a unique list of states (this list does not have all the states so I want just the ones contained in it). Below is a screen shot of the <a href="http://www.linqpad.net/">LINQPad</a> with my Query in it. I simply pressed the green triangle (trained by <a href="http://msdn.microsoft.com/en-us/library/aa174466(SQL.80).aspx">Sql Server Enterprise Manager</a>), and presto, my list! Could not be much easier. This tool will be in my box for a long time.</p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="5" width="400">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://www.peterkellner.net/FilesForWebDownload/LINQPadistotallyawesomeattestingandwriti_11132/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://www.peterkellner.net/FilesForWebDownload/LINQPadistotallyawesomeattestingandwriti_11132/image_thumb.png" width="436" height="462" /></a></td>
<td valign="top" width="200">
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:f6c31e3c-c91c-488b-9956-0209b5fc625f" class="wlWriterSmartContent">
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<p><a title="Amazon.com: C# 3.0 in a Nutshell" href="http://www.amazon.com/exec/obidos/ASIN/0596527578/petkelsblo-20"><img border="0" align="left" src="http://images.amazon.com/images/P/0596527578.01.MZZZZZZZ.jpg" />Amazon.com: C# 3.0 in a Nutshell</a></p>
</td>
</tr>
</tbody>
</table></div>
</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Grab this now!&#160; It&#8217;s a winner, believe me.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/09/20/linqpad-sqlserver-linq-interpreter-nutshell/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 29/38 queries in 0.009 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-22 11:11:08 -->
