Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:13:54+00:00 2026-06-07T23:13:54+00:00

I am running a simple select query thusly: Private Function ReturnTableQuery(ByVal SQL As String)

  • 0

I am running a simple select query thusly:

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 <> 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

The SQL command is:

Select id, application, datetimestamp, status, data, attemptcount from queue where application='reportengine' and status=4 and datetimestamp <= now()  order by datetimestamp limit 1

I sometimes get 0 rows returned.

If I run the exact same query in pgAdmin while it is failing in my program, it returns a row as expected.

If I close and re-open the connection it works, but I can’t determine if there is anything wrong with the connection beforehand.

I could just re-open the connection every time, but I would rather not recreate the connection as often as I would need to.

I am also getting intermittent errors like “unknown server response” which I am catching and re-opening the connection.

Any ideas why the connection is so fragile and is there an inexpensive way to check the actual connection status?

Thx,
Brad

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:13:55+00:00Added an answer on June 7, 2026 at 11:13 pm

    Are you sharing your connection between multiple threads? Npgsql, as other data providers, is not thread safe. I would rank this is the most probable cause of your problems. You should open a connection, use it and then close it. That’s the most scalable pattern when using a connection pool. I hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a simple select query on oracle server A And on Oracle
I am running a simple join query select count(*) from t1 join t2 on
I am using SQL 2000, and I am running a simple select statement on
I'm running a simple query with a join, similar to SELECT t1.a, t2.b FROM
I am running the simple query below select '''' + event_number + '''' +','
I'm running a pretty simple SQL query on my database, and it seems to
I am running a simple DATEDIFF query but it doesn't seem to calculate the
Running SQL Server 2008, and I am definitely a new SQL user. I have
I have a simple query running on both .NET 3.5 and .NET 4, something
I've got a simple select query which executes in under 1 second normally, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.