I need to return the ip connection data of an ODBC Mysql connection to visually verify that I am connected successfully to the right database on the correct server using VB.net.
In VB6 I used to parse the ADOX.Catalog.ActiveConnection string but that does not work in VB.net. No string is returned.
What is the method now used to obtain the IP of a successful ODBC connection? Searching the ObjectBrowser and MSDN is not helpful in this regard.
not an answer - but more problems
The answer below looked like a drop dead easy way to do it.wish it was this easy.I have been bogged down for hours trying to get the DNS resolved - and running into socket errors on windows7 in the resolve code.
poking about I have come across this MSDN code which is a direct approach from ADOX. However it will not compile as it chokes on compiling ConnectionStringSettings protesting that it is not defined even though it is a member of the System.Net.Configuration assembly. What is wrong with the ADOX syntax.
and I used to think vb coding was easier than java! One would have thought MSDN would have given examples of code that compiled.
Imports System.Net
Private Shared Function GetConnectionStringByName(ByVal name As String) As String
GetConnectionStringByName = "OK"
' Assume failure
Dim returnValue As String = Nothing
' Look for the name in the connectionStrings section.
Dim settings As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("MySql")
' If found, return the connection string.
If Not settings Is Nothing Then
returnValue = settings.ConnectionString()
End If
' Return returnValue
End Function
You can execute the sql query,
This will return the hostname of the MySQL server. You can easily resolve the IP from the host name using Dns.Resolve
References: