Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to force Npgsql to use CommandTimeout value from connection string in ASP.NET MVC3 application
    primarykey
    data
    text
    <p>ASP.NET MVC3 application uses npgsql 2.0.12.0 to get data in Mono with mod_mono. Sometimes timeout exceptions below occur. Request duration is 31 seconds if exception occurs.</p> <p>CommandTimeout in connection string is set to 5 minutes using</p> <pre><code> NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder() { CommandTimeout = 5*60, // 5 min Host = Config.Server, Database = Config.DefaultDataBase, UserName = Config.ServerUser, Port = Config.Port, SslMode = SslMode.Prefer, SSL = true, }; </code></pre> <p>How to force npgsql use use timeout 5 minutes and not to throw excpetion after 31 seconds ? In postgresql.con file statement_timeout is not set so it looke like this is not coming from server.</p> <p>Query is executed using ExecuteReader:</p> <pre><code> using (IDbConnection conn = DataAccessBase.CreateConnection()) using (IDbCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(command, paramNames); conn.Open(); using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleResult)) { if (reader.Read()) { string[] names = new string[reader.FieldCount]; for (int i = 0; i &lt; names.Length; i++) { names[i] = reader.GetName(i); } Func&lt;IDataRecord, MyDataContext, T&gt; objInit = InitializerCache&lt;T&gt;.GetInitializer(names, ConvertValue != null); do { // walk the data yield return objInit(reader, this); } while (reader.Read()); } while (reader.NextResult()) { } // ensure any trailing errors caught } } </code></pre> <p>Exception occurs after 31 seconds from start of request.</p> <p>Request header:</p> <pre><code>Connection Keep-alive Accept */* Accept-Encoding gzip,deflate From googlebot(at)googlebot.com User-Agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) </code></pre> <p>Exception:</p> <pre><code>Npgsql.NpgsqlException: A timeout has occured. If you were establishing a connection, increase Timeout value in ConnectionString. If you were executing a command, increase the CommandTimeout value in ConnectionString or in your NpgsqlCommand object. at Npgsql.NpgsqlState.ProcessBackendResponsesEnum (Npgsql.NpgsqlConnector context) [0x00000] in &lt;filename unknown&gt;:0 at Npgsql.NpgsqlReadyState.QueryEnum (Npgsql.NpgsqlConnector context, Npgsql.NpgsqlCommand command) [0x00000] in &lt;filename unknown&gt;:0 at Npgsql.NpgsqlConnector.QueryEnum (Npgsql.NpgsqlCommand queryCommand) [0x00000] in &lt;filename unknown&gt;:0 at Npgsql.NpgsqlCommand.GetReader (CommandBehavior cb) [0x00000] in &lt;filename unknown&gt;:0 at Npgsql.NpgsqlCommand.ExecuteReader (CommandBehavior cb) [0x00000] in &lt;filename unknown&gt;:0 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload