title: Setting ConnectionTimeout for OdbcConnection (System.Data.Odbc) in c# does not work
body: <p>I have a .net 4.0 c# application which needs an odbc connection to mssql 2008. The connection usually works perfect. But when I run a query which usually runs for some minutes (and no, at this point in the project I can't optimise the query runtime) I'll get a timeout after 30 seconds:</p>
  
  <blockquote>
    <p>ERROR [HYT00] [Microsoft][SQL Server Native Client 10.0]Query timeout
    expired</p>
  </blockquote>
  
  <p>I have already tried to change the driver (sqlsrv32.dll, sqlncli10.dll, sqlncli11.dll) for the odbc connection but I get always a similar error.</p>
  
  <p>This is the dummy code I have built to simulate the problem:</p>
  
  <pre><code>using (
      OdbcConnection conn =
          new OdbcConnection("DSN=d3FA;uid=sa;pwd=1234;MARS_Connection=yes;Connection Timeout=37;"))
  {
      conn.ConnectionTimeout = 37;
      conn.Open();
  
      OdbcCommand myCommand = new OdbcCommand("WAITFOR DELAY '00:00:45'", conn);
      myCommand.ExecuteNonQuery();
  }
  </code></pre>
  
  <p>As you can see I have set the Connection Timeout in the connection string and I also set the property of the connection. But it seems that this information (37 seconds) is just ignored from the query execution. The timeout still occurs after 30 seconds. </p>
  
  <p>From Microsoft I have the information that the Windows ODBC API offers the <a href="http://msdn.microsoft.com/en-us/library/ms712631%28VS.85%29.aspx" rel="noreferrer">SQLSetStmtAttr-Function</a> which would allow setting the SQL_ATTR_QUERY_TIMEOUT attribute. Perhaps setting this attribute would solve my problem - but I couldn't find any solution how I could set this value through .net.</p>
  
  <p>Conclusion: Has anybody an idea how to increase the timeout value?</p>