 




<?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>SQL Server with Mr. Denny &#187; Session State</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/sql-server/tag/session-state/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/sql-server</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 17:04:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>ANSI Settings can have all the difference in the world.</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/ansi-settings-can-have-all-the-difference-in-the-world/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/ansi-settings-can-have-all-the-difference-in-the-world/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 14:00:10 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[Session State]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/ansi-settings-can-have-all-the-difference-in-the-world/</guid>
		<description><![CDATA[So a little while back we noticed that we had some high CPU load coming from a single stored procedure in the Session State database.  This single procedure (TempUpdateStateItemLong) was taking up 80% of the CPU time that the database was using (we used Spotlight for SQL Server Enterprise from Quest software).  But in another [...]]]></description>
				<content:encoded><![CDATA[<p>So a little while back we noticed that we had some high CPU load coming from a single stored procedure in the Session State database.  This single procedure (TempUpdateStateItemLong) was taking up 80% of the CPU time that the database was using (we used Spotlight for SQL Server Enterprise from Quest software).  But in another session state database that same procedure was down in the single digits.  So something must be different between them.</p>
<p>I opened them both up in SSMS and the code for the procedures was identical (as you would expect), but there was something different.  The procedure that had the really high CPU % times was compiled with the SET QUOTED_IDENTIFIER ON setting, while the procedure that had the really low CPU % times was compiled with the SET QUOTED_IDENTIFIER OFF setting.</p>
<p>I have no idea why there was a difference, but I changed the one which was ON to OFF and pushed the procedure into the database.  As soon as I did the CPU % for that procedure dropped down into the single digit range where it should have been.</p>
<p>Let this be a lesson, those setting definitely matter.  And don&#8217;t trust that they are correct, even in Microsoft provided code like Session State.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/ansi-settings-can-have-all-the-difference-in-the-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lets get session state out of the database, and into memory where it belongs.</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/lets-get-session-state-out-of-the-database-and-into-memory-where-it-belongs/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/lets-get-session-state-out-of-the-database-and-into-memory-where-it-belongs/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 14:00:38 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[Paul Randal]]></category>
		<category><![CDATA[Session State]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/lets-get-session-state-out-of-the-database-and-into-memory-where-it-belongs/</guid>
		<description><![CDATA[One of the all to common configuration mistakes that are made is to put the session state within the SQL Server when a website begins to scale to multiple web servers. Some background For those that don&#8217;t know what session state is, let me take a step back and fill you in.  Session state allows [...]]]></description>
				<content:encoded><![CDATA[<p>One of the all to common configuration mistakes that are made is to put the session state within the SQL Server when a website begins to scale to multiple web servers.</p>
<p><strong>Some background</strong></p>
<p>For those that don&#8217;t know what session state is, let me take a step back and fill you in.  Session state allows the web developer to store values in variables up on the web server, but in a shared location so that it doesn&#8217;t matter what web server the end user connects to the values are all there and the web servers understand the session information from each other.  This is very important for shopping websites, or pretty much any site with a login prompt and a load ballancer that is configured to send the users connection to the next available web server.</p>
<p><strong>What is the problem?</strong></p>
<p>The problem becomes that most people when they need to scale out session state opt to put the session state information into SQL Server because that is a nice easy repository that is probably already up and running, not to mention that the session state code in ASP.NET easily supports it.  The issue with putting the session state information into SQL Server is that you don&#8217;t give a crap about persisting the session state information to disk.  The information doesn&#8217;t get persisted more than an hour or so, and if the information within the database is lost, the only impact is that any values in session variables is lost.</p>
<p><strong>So what are the options?</strong></p>
<p>There are a few options besides using SQL Server for session state.</p>
<ol>
<li>Keep using the in-process option.</li>
<li>Use the ASP.NET Session State Service</li>
</ol>
<p>The easiest option is to keep using the in-process option in IIS for session information.  This means that you will need to configure what are called sticky sessions on the load balancer so that the user always goes to the same web server every time.  In the event that a web server fails, all the session information for those users would be lost, and they would need to start over by logging back into the site, or they would have an empty shopping cart, or whatever the site does.</p>
<p>The ASP.NET Session State Service is a Windows service that provides a memory only session state repository so that session information isn&#8217;t ever written to disk, and it isn&#8217;t kept on the web server.  You can either stand up a dedicated machine for this, or setup a couple and cluster the service manually so that you have an HA solution for your session state service.  If you have an existing SQL Server cluster you can even use this cluster for it, if you don&#8217;t have anywhere better to put it.  Just configure the cluster to have the SQL Server run on one node as the preferred node, and have the session state run on another node as its preferred node.  This way the services won&#8217;t ever run on the same node unless the other node is offline.  The session state service doesn&#8217;t take a lot of CPU power, and the amount of RAM it needs to be completely dependent on the amount of information that you are stuffing into session variables on the web servers.</p>
<p>In either case, either solution is better than putting the session state information into a SQL Server database.  The information doesn&#8217;t need to be written to disk, ever.  The information that is written into the session state database is in a blob binary form, not any sort of relational form so you can&#8217;t really do anything with it.</p>
<p><strong>How do I know if sessions state is in SQL?</strong></p>
<p>That is an easy one.  You&#8217;ll have some funky database, probably in simple recovery mode usually name aspnetdb (maybe with a prefix and/or a suffix).</p>
<p><strong>What other problems can session state cause?</strong></p>
<p>Well first it&#8217;ll take away buffer pool resources from your other databases.  Because the session state database is hit very hard the data from the database will always be in memory.  How ever much data is in the session state database, you are missing that much buffer pool space for your other databases.  Because of the way that session state works, every single time a page is clicked on the website, at least one call is made to the session state database pretty much forcing the database server to keep the data from the database in the buffer pool.</p>
<p>Another problem that you can see if ghost records.  Paul Randal describes ghost records perfectly on his blog post <a href="http://www.sqlskills.com/BLOGS/PAUL/post/Inside-the-Storage-Engine-Ghost-cleanup-in-depth.aspx">Ghost cleanup in depth.</a></p>
<blockquote><p>When a record is deleted, apart from  it being marked as a ghost record, the page that the record is on is  also marked as having ghost records in one of the allocation maps &#8211; the  PFS page (post coming soon!) &#8211; and in its page header. Marking a page as  having ghost records in a PFS page also changes the database state to  indicate that there are some ghost records to cleanup &#8211; somewhere.  Nothing tells the ghost cleanup task to clean the specific page that the  delete happened on - yet. That only happens when the next scan  operation reads the page and notices that the page has ghost records. </p></blockquote>
<p>He also talks about how to fix the problem in the same blog post, so I&#8217;ll leave you to <a href="http://www.sqlskills.com/BLOGS/PAUL/post/Inside-the-Storage-Engine-Ghost-cleanup-in-depth.aspx">click through</a> for all that information.</p>
<p>Another problem goes back to the fact that the SQL Server will be persisting everything to disk, and with the information in this database changing all the time, as the website grows you&#8217;ll need faster and faster disks under the session state database just to keep up.  As the site grows more popular you will end up spending more and more money on faster and faster disks, just to keep the session state working, much less anything else on the SQL Server.  You may even get to the point where you actually need a dedicated SQL Server just to run the session state database.</p>
<p>Another problem is good old locking and blocking.  SQL Server likes to take page level locks when it does insert, update and delete operations.  Well, unless each page on disk only has a single row in it you are going to have processes being blocked for short periods of time as other users session state information is updated.  You can work around this to some extent by hacking the session state database&#8217;s stored procedures and forcing row locks, but now you are taking more locks (and more memory for locks), etc.</p>
<p><strong>How do I change to the session state server?</strong></p>
<p>First you need to install the service on the server that will be your session state server.  On Windows 2008 just install all the .NET components and that should do the trick.  You&#8217;ll probably want to start the service as well.  When you bring up the list of services it is the one called &#8220;ASP.NET State Service&#8221;.<br />
<a href="http://www.mrdenny.com/blog/images/Session Service in list.jpg"><img src="http://www.mrdenny.com/blog/images/Session Service in list.jpg" border="0" alt="" /></a></p>
<p>Then on each web server you&#8217;ll want to change the session state information.  You can either use IIS Manager to do this, or change the web.config.  However you configured session state the first time, that&#8217;s how you&#8217;ll want to change it this time.</p>
<p>To use the IIS Manager select the website (or application) to configure and double click on the &#8220;Session State&#8221; icon on the right (shown below).<br />
<a href="http://www.mrdenny.com/blog/images/SessionStateIcon.jpg"><img src="http://www.mrdenny.com/blog/images/SessionStateIcon.jpg" border="0" alt="" /></a></p>
<p>From there select &#8220;State Server&#8221; from the list and change &#8220;localhost&#8221; to the server you&#8217;ll be using for session state.  If you have changed the TCP port number from 42424 to something else you can adjust that here as well.<br />
<a href="http://www.mrdenny.com/blog/images/SessionStateSettings.jpg"><img src="http://www.mrdenny.com/blog/images/SessionStateSettings.jpg" border="0" alt="" width="158" height="120" /></a></p>
<p>To set the session state setting via the web.config file find the existing session state information and edit it, or add in the session state information.  Set the &#8220;mode&#8221; to &#8220;StateServer&#8221; and set the &#8220;stateConnectionString&#8221; to the same value that goes in the IIS config setting.</p>
<pre>&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/&gt;
  &lt;/system.web&gt;
&lt;/configuration&gt;
</pre>
<p>Hopefully I&#8217;ve convinces you to move your session state information out of SQL Server and into a repository that it actually belongs in.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/lets-get-session-state-out-of-the-database-and-into-memory-where-it-belongs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>IIS 7 and Session State</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/iis-7-and-session-state/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/iis-7-and-session-state/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 11:00:01 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[IIS 7]]></category>
		<category><![CDATA[Session State]]></category>
		<category><![CDATA[Windows 2008]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/iis-7-and-session-state/</guid>
		<description><![CDATA[While working on moving my companies data center from Texas to California we ran across an issue with IIS 7 on Windows 2008 because we were using the ASPState database to handle session state. If you&#8217;re like me you probably upgrade when you have the chance.  If you&#8217;re like my company you don&#8217;t run just [...]]]></description>
				<content:encoded><![CDATA[<p>While working on moving my companies data center from Texas to California we ran across an issue with IIS 7 on Windows 2008 because we were using the ASPState database to handle session state.</p>
<p>If you&#8217;re like me you probably upgrade when you have the chance.  If you&#8217;re like my company you don&#8217;t run just one website per server.  In our case this cluster of web servers runs 6 different sites, and the session state for one of them keeps resetting just about every page view.</p>
<p>Apparently one of the values which is used to create the session id is the ID number of the website in IIS.  Up through IIS 6 this number was a hash of the name of the site, so as long as the sites all had the same name you were set.  In IIS 7 this ID number is now just a running number based on the order you create the websites in.  So if you create the websites in a different order on one or more machines then your ASPState information will keep expiring since the hash values don&#8217;t match correctly.</p>
<p>The good news is that you can change the ID number by clicking the Advanced Settings link on the right hand side.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/iis-7-and-session-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
