G
Guest
I have a module that handles creating a sql connection object as per below
code. What do you think, is there a better way to do this?
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration.ConfigurationManager
Public Module DBConnections
'Handles Opening and Closing connections to the Database
Public objConnection As SqlConnection
'Get the Connection string from the web config file
Public ConnStr As String = ConnectionStrings("DBString").ConnectionString
Public Sub openDB()
If objConnection Is Nothing = True Then
objConnection = New SqlConnection(ConnStr)
objConnection.Open()
Else
If objConnection.State <> ConnectionState.Open Then
objConnection.Open()
End If
End If
End Sub
Public Sub closeDB()
If objConnection Is Nothing = False Then
objConnection.Close()
objConnection = Nothing
End If
End Sub
End Module
code. What do you think, is there a better way to do this?
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration.ConfigurationManager
Public Module DBConnections
'Handles Opening and Closing connections to the Database
Public objConnection As SqlConnection
'Get the Connection string from the web config file
Public ConnStr As String = ConnectionStrings("DBString").ConnectionString
Public Sub openDB()
If objConnection Is Nothing = True Then
objConnection = New SqlConnection(ConnStr)
objConnection.Open()
Else
If objConnection.State <> ConnectionState.Open Then
objConnection.Open()
End If
End If
End Sub
Public Sub closeDB()
If objConnection Is Nothing = False Then
objConnection.Close()
objConnection = Nothing
End If
End Sub
End Module