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 1009181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:53:07+00:00 2026-05-16T08:53:07+00:00

After running the following sub (VS debugger), I try to detach the database in

  • 0

After running the following sub (VS debugger), I try to detach the database in SSMS, but it shows the connection open still and won’t let me detach. If I close program in debugger, the database shows no connections. I check the dataadapter’s connection in the finally block and is shows closed. What gives

Private Function ClientMasterDBFiles(ByVal MasterClientDBConnection As String, ByVal DBName As String) As DataTable
    Dim da As SqlDataAdapter
    Dim ds As DataSet

    Try
        ds = New DataSet
        da = New SqlDataAdapter
        da.SelectCommand = New SqlCommand
        With da.SelectCommand
            .CommandType = CommandType.StoredProcedure
            .Connection = New SqlConnection(MasterClientDBConnection)
            .CommandText = "QT_DataSync_GetDBFileLocations"
            .Parameters.Add(New SqlParameter("@DBName", SqlDbType.VarChar, 100))
            .Parameters.Item("@DBName").Direction = ParameterDirection.Input
            .Parameters.Item("@DBName").Value = DBName
            .CommandType = CommandType.StoredProcedure
            .CommandTimeout = 10
        End With

        da.Fill(ds)

        If ds.Tables.Count > 0 Then
            Return ds.Tables(0)
        End If

    Catch ex As Exception
        m_ErrorLog.HandleException(ex)
        Throw
    Finally
        If Not da Is Nothing Then da.Dispose()
        If Not ds Is Nothing Then ds.Dispose()
        da = Nothing
        ds = Nothing
    End Try
End Function
  • 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-16T08:53:08+00:00Added an answer on May 16, 2026 at 8:53 am

    EDIT

    I was wrong all along.
    Your problem is that the .Net SqlClient classes pool connections.


    You need to explicitly close the SqlCommand’s Connection, like this:

    If Not da Is Nothing Then da.SelectCommand.Connection.Close()
    

    However, you should use a Using statement instead, like this:

    Dim ds As DataSet
    
    Try
        Using da As SqlDataAdapter, _
              da.SelectCommand = New SqlCommand, _
              da.Connection = New SqlConnection(MasterClientDBConnection)
    
            With da.SelectCommand
                .CommandType = CommandType.StoredProcedure            
                .CommandText = "QT_DataSync_GetDBFileLocations"
                .Parameters.Add(New SqlParameter("@DBName", SqlDbType.VarChar, 100))
                .Parameters.Item("@DBName").Direction = ParameterDirection.Input
                .Parameters.Item("@DBName").Value = DBName
                .CommandType = CommandType.StoredProcedure
                .CommandTimeout = 10
            End With
    
            da.Fill(ds)
    
            If ds.Tables.Count > 0 Then
                Return ds.Tables(0)
            End If
        End Using
    Catch ex As Exception
        m_ErrorLog.HandleException(ex)
        Throw
    End Try
    

    Also, you shouldn’t dispose the DataSet, since you’re returning one of its tables.

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

Sidebar

Related Questions

I'm running the following code on Ubuntu 10.10, using OpenJDK 1.6.0_18: package mypkg; public
I'm trying to get autotest back up and running after moving my project to
Good morning, I wrote the following LINQ query public static Func<String, IEnumerable<String>> ListaCorreccoes =
This seems like it should be straight-forward, but I'm stumped. I have a link
I'm having a hard time getting what I want out of the python subprocess
I have a .NET 4 WCF service that maintains a thread-safe, in-memory, dictionary cache
I've found myself in a bit of a predicament. I have a table used
I was successfully able to remove read only attribute on a file using the
I want to force push, for example, my tag 1.0.0 to my remote master
I'm having difficulty mocking the PDO object with PHPUnit. There doesn't seem to be

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.