title: NPGSQL select query intermittently returns no rows
body: <p>I am running a simple select query thusly:</p>
  
  <pre><code>Private Function ReturnTableQuery(ByVal SQL As String) As DataTable
  
      Dim rs As DataTable = New DataTable
      Dim Adapter As NpgsqlDataAdapter = New NpgsqlDataAdapter
  
      Try
          If conn Is Nothing Then
              ConnectDatabase()
          End If
          If conn.State &lt;&gt; ConnectionState.Open Then
              ConnectDatabase()
          End If
          Adapter.SelectCommand = New NpgsqlCommand(SQL, conn)
          Adapter.SelectCommand.CommandTimeout = 10
          Adapter.Fill(rs)
      Catch ex As Exception
          PreserveStackTrace(ex)
          Throw ex
      End Try
  
      Return rs
  
  End Function
  </code></pre>
  
  <p>The SQL command is: </p>
  
  <pre><code>Select id, application, datetimestamp, status, data, attemptcount from queue where application='reportengine' and status=4 and datetimestamp &lt;= now()  order by datetimestamp limit 1
  </code></pre>
  
  <p>I sometimes get 0 rows returned. </p>
  
  <p>If I run the exact same query in pgAdmin while it is failing in my program, it returns a row as expected.</p>
  
  <p>If I close and re-open the connection it works, but I can't determine if there is anything wrong with the connection beforehand.</p>
  
  <p>I could just re-open the connection every time, but I would rather not recreate the connection as often as I would need to.</p>
  
  <p>I am also getting intermittent errors like "unknown server response" which I am catching and re-opening the connection. </p>
  
  <p>Any ideas why the connection is so fragile and is there an inexpensive way to check the <strong><em>actual</em></strong> connection status?</p>
  
  <p>Thx,
  Brad</p>