Connection to database not closing...
Connection to database not closing...
Connection to database not closing...
Connection to database not closing...
Connection to database not closing...
Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing...
Connection to database not closing... Connection to database not closing...
Connection to database not closing...
Go Back  Xtreme Visual Basic Talk > > > Connection to database not closing...


Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2014, 06:23 AM
lidds lidds is offline
Centurion
 
Join Date: May 2004
Posts: 100
Default Connection to database not closing...


I am stuggling to find out what I am doing wrong here and think a fresh pair of eyes might help.

I have a class called DBAccess which I am using to connect to a SQL Server database, the DBAccess class contains the following code:

Code:
Public Class DBAccess

    Private connStr As String = Nothing
    Public myConn As New SqlClient.SqlConnection

    Public Sub New()

    End Sub

    Public Function Connect(ByVal DBName As String) As Boolean
        ' connect to database
        connStr = "Data Source=myServer;initial catalog='" & DBName & "';user id=myUsername;password=myPassword"        
        myConn.ConnectionString = connStr

        Try
            myConn.Open()
            Return True
        Catch e As Exception
            MsgBox(e.ToString)
            Return False
        End Try
    End Function

    Public Function DisConnect() As Boolean
        ' connect to database
        myConn.Close()
        Return True 
    End Function
End Class
I then am calling this class using the below code

Code:
        ' Check connection to database
        Dim myDB As New DBAccess()
        If myDB.Connect("myDatabaseName") = False Then
            Return False
        Else
            myDB.DisConnect()
            Return True
        End If
The problem that I have is this seems to not close the connect for some reason and I don't know why. Does anyone know why this might be?

Thanks in advance

Simon
Reply With Quote
  #2  
Old 01-21-2014, 10:31 AM
PlausiblyDamp's Avatar
PlausiblyDampConnection to database not closing... PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

By default it is pooling the database connections, when you close a connection it isn't immediately closed but kept alive ready to be reused.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Connection to database not closing...
Connection to database not closing...
Connection to database not closing... Connection to database not closing...
Connection to database not closing...
Connection to database not closing...
Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing... Connection to database not closing...
Connection to database not closing...
Connection to database not closing...
 
Connection to database not closing...
Connection to database not closing...
 
-->