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:
I then am calling this class using the below code
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
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