Query Timeout OptionsThe c-treeSQL Server supports a timeout option for an executing query. This feature can ensure that an unintended query statement does not consume excessive processing time. With c-treeACE SQL ODBC you can set the query timeout value for the statement with the SQLSetStmtAttr() c-treeACE SQL ODBC API function and the SQL_ATTR_QUERY_TIMEOUT parameter set to the number of seconds to wait for the query to execute before returning to the application. A value of 0 indicates no timeout value, which is also the default. The following example code will set a query timeout value of five seconds for the referenced statement handle. ODBC Example /* Set the Query timeout to 5 seconds */ SQLSetStmtAttr(hstmt, (void*)SQL_ATTR_QUERY_TIMEOUT, 5, 0); Using ODBC through ADO.NET, you can specify the OdbcConnection.CommandTimeout property to set a query timeout value on an ODBC statement as demonstrated with the following syntax. ODBC via ADO .NET Example OdbcConnection myConnection = new OdbcConnection(); myConnection.ConnectionString = "DSN=c-treeSQL ODBC Database"; myConnection.Open(); OdbcCommand oc = new OdbcCommand("SELECT TOP 50000 FROM my_big_table WHERE this < that AND this_string = 'that_string' ORDER BY foo”, myConnection);
// Set a query timeout of 5 seconds. oc.CommandTimeout = 5; try {
oc.ExecuteReader(); } catch (Exception ex) {
// Log some error } |
|||