find ip of connected MYSQL database in VB.net

227 views Asked by At

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
1

There are 1 answers

0
bansi On

You can execute the sql query,

SHOW VARIABLES LIKE 'hostname'

This will return the hostname of the MySQL server. You can easily resolve the IP from the host name using Dns.Resolve

References:

  1. 13.7.5.41 SHOW VARIABLES Syntax
  2. 5.1.4 Server System Variables