title: ODBC Connection to DB2 Hangs
body: <p>I have a function I use to send write queries to DB2 through ODBC, and it gets hung up in this function from time to time if I lose my connection to DB2. I am sending 60 as my timeout to the function, but it never times out. It just hangs up my thread indefinitely, and I'm not sure of a good way to force this function to give up.</p>
  
  <pre><code>public int WriteQuery(string query, string dbConnStr, int timeout)
  {
      int rowsAffected = -1;
      OdbcConnection conn = new OdbcConnection(dbConnStr);
  
      try
      {
              conn.Open();
              OdbcCommand command = new OdbcCommand(query, conn);
              command.CommandTimeout = timeout;
  
              OdbcTransaction trans = conn.BeginTransaction();
              command.Transaction = trans;
  
              OdbcDataAdapter adapter = new OdbcDataAdapter(command);
              adapter.UpdateCommand = command;
  
              rowsAffected = command.ExecuteNonQuery();
              trans.Commit();
          }
          catch(Exception)
          {
              throw;
          }
          finally
          {
              conn.Close();
              conn.Dispose();
          }
  
          return rowsAffected;
      }
  }
  </code></pre>