title: Website loses connection to database sporadically
body: <p>I've been struggling with this error for just over a month now and can't get it figured out.</p>
  
  <p><strong>Background/Architecture:</strong></p>
  
  <ul>
  <li>MVC 4 application</li>
  <li>NHibernate</li>
  <li>FluentNHibernate</li>
  <li>SQL Server 2008 R2</li>
  <li>Azure website</li>
  </ul>
  
  <p>Sporadically throughout the day, my views are throwing errors because when they try to read/display properties on my objects, it says:</p>
  
  <blockquote>
    <p>NHibernate.Exceptions.GenericADOException: could not initialize a
    collection: [WrestleStat.BL.School.Schedule#54][SQL: SELECT
    ...(removed to keep this short)....] --->
    System.Data.SqlClient.SqlException: Timeout expired. The timeout
    period elapsed prior to completion of the operation or the server is
    not responding. This failure occurred while attempting to connect to
    the routing destination. The duration spent while attempting to
    connect to the original server was - [Pre-Login] initialization=3;
    handshake=23; [Login] initialization=0; authentication=0; [Post-Login]
    complete=1; ---> System.ComponentModel.Win32Exception: The wait
    operation timed out
    --- End of inner exception stack trace --- at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection, Action`1 wrapCloseInAction) at
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
    stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
    System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject
    stateObj, UInt32 error) at
    System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at
    System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at
    System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at
    System.Data.SqlClient.TdsParserStateObject.TryReadByteArray(Byte[]
    buff, Int32 offset, Int32 len, Int32&amp; totalRead) at
    System.Data.SqlClient.TdsParserStateObjec</p>
  </blockquote>
  
  <p>2 weeks ago, I was running my website on AppHarbor, and I thought it was because I was on their "basic" (free) plan. The problem seemed to go away if I'd up my worker threads from 1 to 2. Because of that, I decided to switch over to Azure (I was going to anyway, but not this early). Since the switchover to Azure, the problem has not gone away.</p>
  
  <p>I get approximately a dozen of these errors per day on the site. It appears as though that the errors always occur when the razor views are trying to access properties of an object that it's trying to read/display, as opposed to throwing the error inside the controller trying to retrieve the data. Maybe it has something to do with the lazy loading??? But why would that matter, why would the connection be lost in that extremely short timeframe from retrieving the data, then presenting it on the page?</p>
  
  <p>I'm at a loss on how to debug this issue, because it obviously never happens in my development environment. I'm going to switch over to Dapper eventually, but I'm not able to do/start that for at least another 3 months.</p>
  
  <p>Any ideas here?</p>
  
  <p>Edit: here's the website <a href="http://www.wrestlestats.com" rel="nofollow">http://www.wrestlestats.com</a></p>