<p><strong>Update</strong>: Looks like the query does not throw any timeout. The connection is timing out.</p>

<p>This is a sample code for executing a query. Sometimes, while executing time consuming queries, it throws a timeout exception.</p>

<p>I <strong>cannot</strong> use any of these techniques:
1) Increase timeout.
2) Run it asynchronously with a callback. This needs to run in a synchronous manner.</p>

<p>please suggest any other techinques to keep the connection alive while executing a time consuming query?</p>

<pre><code>private static void CreateCommand(string queryString,
    string connectionString)
{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        SqlCommand command = new SqlCommand(queryString, connection);
        command.Connection.Open();
        command.ExecuteNonQuery();
    }
}
</code></pre>

```
```
command.CommandTimeout *= 2;
```
```
That will double the default time-out, which is 30 seconds.
Or, put the value for CommandTimeout in a configuration file, so you can adjust it as needed without recompiling.