I have a simple VB.net windows form application. I have a method for opening the connection to the database. I am using two MySql connections. In the method below it can be seen that My primary connection is opened and after that my secondary connection is opened. Both connections have different connection strings but in very rare cases these connection strings can be same so in that I don't want to open the connection twice.
Dim MySqlConnPrimary As New MySqlConnection
Dim MySqlConnSecondary As New MySqlConnection
Public Sub OpenConnection(ByVal strConnectionStringPrimary As String, ByVal strConnectionStringSecondary As String)
Try
With MySqlConnPrimary
.ConnectionString = strConnectionStringPrimary
.Open()
End With
With MySqlConnSecondary
.ConnectionString = strConnectionStringSecondary
.Open()
End With
Catch ex As Exception
End Try
End Sub
Mostly the connection strings will be different but in case the connection strings are same then I don't want to open the connections multiple times. How should I achieve this? Should I assign MySqlConnPrimary to MySqlConnSecondary incase the connection strings are same?
MySqlConnPrimary.ConnectionStateCheck it using if..else block and code the necessary actions according to it.