title: Timeouts with deployed code but not during debugging
body: <p>I have a C# winforms application with the following relevant items:</p>
  
  <ul>
  <li>VS2010 SP1, .NET 3.5</li>
  <li>Fluent NHibernate 1.0 (with NH 3.0, maybe this is part of the issue)</li>
  <li>Deployed with ClickOnce</li>
  <li>SQL Server 2008 R2 database</li>
  </ul>
  
  <p>I have the deployed copy installed on my machine (via ClickOnce) and am running another copy via the VS2010 debugger side-by-side.  It is the same code-base.  I just published yesterday and have not changed any code since publishing.</p>
  
  <p>On the same machine (again, running side-by-side), pointing to the same SQL Server instance, the deployed copy of my app times out trying to write to the database.  The copy started through the debugger writes just fine.  This is repeatable, every time.</p>
  
  <p>In the real world only a couple of people are reporting the timeout.  They're in the same department, right in the same place in the building.  They're the only ones (ok, that I know of).  I'm using the same SQL instance to debug this that they're using.</p>
  
  <p>All files (except .pdb's) are included in the deployment for all projects in the solution.</p>
  
  <p>This is the stack trace for the outer exception (I don't have one for any inner exceptions yet):</p>
  
  <pre><code>Stack Trace:
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
     at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
     at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
     at System.Data.SqlClient.SqlDataReader.get_MetaData()
     at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
     at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
     at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
     at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
     at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
     at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
     at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
     at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
     at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 
  </code></pre>
  
  <p>What could cause that timeout in one but not the other?  On the same machine, running at the same time (or even one right after the other).  I've even run it locally from the build\bin\ folder with no timeout, just like through the debugger.  It's only the deployed copy that produces the timeout.</p>
  
  <p><strong>UPDATE:</strong><br>
  I've been able capture a SQL Profiler trace for the production environment and everything is getting to SQL except for the actual write to the database, which does happen on a background thread.  The method that performs the save (which can consist of a combination of INSERTS and/or UPDATES) is getting called as I see in the trace a query in that method that gets run just before the save is done.   I'm working on capturing the entire exception stack now.</p>
  
  <p><strong>UPDATE 2:</strong><br>
  I've finally reproduced the error in the debugger and have isolated where the exception is being thrown.  The query that I mentioned above which happens immediately before the save is causing the timeout.  That's good, now I can fix that and move on.</p>
  
  <p>The question remains, though: why it was thrown in a process running release code and not in a debug process running the exact same code base.</p>