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

  • Home
  • SEARCH
  • 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 6710251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:00:00+00:00 2026-05-26T08:00:00+00:00

I am performing a simple exercise of opening an SQL Server database connection, pulling

  • 0

I am performing a simple exercise of opening an SQL Server database connection, pulling the first record of a table from a DataReader object, and then closing the object. However, I have noticed that theres bit of a delay, about 5 seconds or so, in closing the connection. However, the delay only occurs after the command object executes the specified query. I’ve worked in a setup like this before and don’t remember there being such a long delay while closing the connection.

   Public Sub TestDb()
    Dim cnStrBuilder As New SqlClient.SqlConnectionStringBuilder
    Dim cn As New SqlClient.SqlConnection
    Dim sqlSelectName As New SqlClient.SqlCommand
    Dim drName As SqlClient.SqlDataReader
    Dim newName As New SymName
    Dim i As Integer

    cnStrBuilder.UserID = "sa"
    cnStrBuilder.ConnectTimeout = 30
    cnStrBuilder.Password = ""
    cnStrBuilder.PersistSecurityInfo = True
    cnStrBuilder.DataSource = "EMARKET\FL_DB"
    cnStrBuilder.InitialCatalog = "EmailMarketing"

    sqlSelectName.CommandType = CommandType.Text
    sqlSelectName.CommandText = "SELECT * FROM [NAME]"

    System.Console.WriteLine(cnStrBuilder.ConnectionString)

    cn.ConnectionString = cnStrBuilder.ConnectionString

    Try
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        System.Console.WriteLine("Connection success")

        sqlSelectName.Connection = cn

        System.Console.WriteLine("Execute Reader")
        drName = sqlSelectName.ExecuteReader

        If drName.HasRows = True Then
            System.Console.WriteLine("Read Row")
            drName.Read()

            For i = 0 To drName.FieldCount - 1
                Console.WriteLine(drName.Item(i).ToString)
            Next
        End If

        System.Console.WriteLine("Closing connection")

        sqlSelectName.Connection.Close()

    Catch ex As Exception
        System.Console.WriteLine("Something Happened")
        System.Console.WriteLine(ex.Message)
    End Try

System.Console.WriteLine("Done.")

End Sub

If I omit the lines

'System.Console.WriteLine("Execute Reader")
'drName = sqlSelectName.ExecuteReader
'
'If drName.HasRows = True Then
'    System.Console.WriteLine("Read Row")
'    drName.Read()
'
'    For i = 0 To drName.FieldCount - 1
'        Console.WriteLine(drName.Item(i).ToString)
'    Next
'End If

The connection closes almost imediately. What gives? I have narrowed it down to the where the .ExecuteReader line that causes the delay in the connection close. Whats causing the delay and how do I resolve it?

  • 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-05-26T08:00:00+00:00Added an answer on May 26, 2026 at 8:00 am

    You’re telling SQL Server to retrieve the entire table. Yet after the first row, you stop, and close the connection. Like you, I would expect the connection to close immediately, but perhaps the server is busy spooling the table to a place where it can return your data quickly.

    Does the connection still close slowly if you only ask the server for one row? F.e.

     sqlSelectName.CommandText = "SELECT TOP 1 * FROM [NAME]"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this is following on from my previous question reguarding performing a simple ajax
I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C#
When performing many inserts into a database I would usually have code like this:
While working on a simple programming exercise, I produced a while loop (DO loop
I'm dealing with physical entities, such as time, speed and distance, and performing simple
I have a simple form which accepts a Title and a Contents variable from
I have a very simple server/client performance test using boost::asio on Windows and it
In Solr, when performing a proximity search, is there a simple way to highlight
I have a simple script which copies a file from one SMB mount to
I'm performing matrix multiplication with this simple algorithm. To be more flexible I used

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.