C# SQL connection timeout
<p>I have a very strange case of SQL connection timeout from an application written in C# .NET.</p>

<p>The <code>SqlCommand.ExecuteNonQuery()</code> is being used to sequentially execute several scripts in SQL Server, one after another. Each script contains a command to create just one table (no data update/insert/delete operations at all). For some reason, at one of the scripts, the <code>SqlCommand.ExecuteNonQuery</code> throws a timeout exception. </p>

<p>When I execute creation of all these tables in SQL Server Management Studio, they get executed just fine and almost instantaneously.</p>

<p>Does anyone has an idea what could be causing timeout when the tables are created from the application?</p>

<p>All sql scripts look similar like following:</p>

<p>SQL:</p>

<pre><code>create table dbo.Test  
(  
  Code varchar(10) not null  
, Name varchar(50) not null  
, other columns...  

  primary key  
, unique key  
, foreign key
)
</code></pre>

<p>The scripts are shipped from C# using this code:</p>

<pre><code>try
{
  using (SqlConnection conSQL = new SqlConnection ("[connection string]"))
  {
     using (SqlCommand cmdSQL = new SqlCommand(sSQL, conSQL))
     {
       cmdSQL.CommandTimeout = iTimeOut;
       conSQL.Open();

       cmdSQL.ExecuteNonQuery(); // this is where it jumps to catch part and                                                                            
                                 // throws out timeout exception
       conSQL.Close();
     }
  }
}
catch(Exception ex)
{
  throw (ex);
}            
</code></pre>

<p>This is happening on the Test server, meaning nothing else is happening on the server while the application is executing these scripts.</p>