Execution Timeout via ASP.NET codebehind that does not occur in SQL Server Management Studio
<p>When running my query directly in SQL Server Management Studio, it works fine and takes about 4 seconds.</p>

<p>When I run it within my ASP.NET app I get: </p>

<blockquote>
  <p>Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.</p>
</blockquote>

<p>Even when I make sure I've added a timeout to the connectionstring, see my code:</p>

<p><code>web.config</code>:</p>

<pre><code>&lt;connectionStrings&gt;
    &lt;add name="conn1" 
         connectionString="data source=(local)\sqlexpress;Initial Catalog=mydb;User Id=myuser;Password=mypwd;" 
         providerName="System.Data.SqlClient" /&gt;
&lt;/connectionStrings&gt;
</code></pre>

<p>Code behind:</p>

<pre><code>Public Shared Function GetConnection() As SqlConnection
    Dim MyConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conn1").ToString)
    Return MyConnection
End Function


Dim myConnection As SqlConnection = GetConnection()
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings("conn1").ToString + "Connection Timeout=900" 'timeout in seconds
</code></pre>

<p>Why does this behavior differ?</p>