asked on
Friend Class Connection
Private Shared m_Connection As SqlConnection
Private Shared m_LastError As String
'Private connDialog As SqlConnectionStringBuilder
''' <summary>
''' Shared method that returns a reference to an SqlConnection object for the Travel Database.
''' </summary>
''' <returns></returns>
''' <remarks>If this is the first time the method is called, a new SqlConnection is constructed.</remarks>
Public Shared Function GetConnection() As SqlConnection
If m_Connection Is Nothing Then
Try
m_Connection = New SqlConnection(My.Settings.TravelConnectionString)
Catch ex As Exception
m_LastError = ex.Message
End Try
End If
Return m_Connection
End Function
''' <summary>
''' Opens the database connection. Checks first to see if the connection is already open.
''' </summary>
''' <remarks></remarks>
Public Shared Sub Open()
If m_Connection.State = ConnectionState.Closed Then
m_Connection.Open()
End If
End Sub
''' <summary>
''' Closes the database connection.
''' </summary>
''' <remarks></remarks>
Public Shared Sub Close()
m_Connection.Close()
End Sub
End Class