Perhaps this is the complete wrong way of doing things, and if so could you perhaps point me in the correct (elegant) way. :)
I have a module in my vb.net project. The module deals with db connections. The idea is for other modules to make use of this module when connections need to be created.
For each database type I have function that opens the db connection. As an example I have this function that opens an oracle connection.
Friend Function OracleConnection(ByVal HostAddress As String, ByVal PortNumber As String, ByVal DBName As String, ByVal UserId As String, ByVal Password As String) As OracleConnection
Try
OracleConnection = New OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" & HostAddress & ")(PORT=" & PortNumber & "))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & DBName & ")(FAILOVER_MODE=(TYPE=select)(METHOD=BASIC)(RETRIES=180)(DELAY=5))));User Id=" & UserId & ";Password=" & Password & ";")
OracleConnection.Open()
OracleConnection = OracleConnection
Catch ex As OracleException
MsgBox(ex.Message, MsgBoxStyle.Critical)
OracleConnection = Nothing
End Try
Return OracleConnection
End Function
Creating the connetion seems to work fine. The problem I have is that I am now not sure how to close the connection that got created by this function.