0

I am using TNS Names to connect to Oracle DB. An entry that is used by application is using failover scenario with 3 DB IP addresses, all virtual.

I am trying to get and display these DB IP addresses but when I use the host name that I get from Oracle connection object, I get DB server's physical IP address.

Let's say physical address 22.23.24.25 and it has 3 VMs: 22.23.24.50, .51 and .52.

In TNSNAMES.ORA file I have:

ABCD = 
(DESCRIPTION =
    (ADDRESS_LIST = 
      (FAILOVER = off)
      (LOAD_BALANCE = off)
      (ADDRESS = (PROTOCOL = TCP)(HOST =22.23.24.50)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST =22.23.24.51)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST =22.23.24.52)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = abcd)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
      )
    )
)

I tried:

public static string GetDBHost()
{
    string sHostName = string.Empty;
    OracleDbContext dbContext = new OracleDbContext();

    try
    {
        dbContext.Open();
        sHostName = dbContext.DbConnection.HostName;
    }
    catch (Exception e)
    {
    }
    finally
    {
        dbContext.Close();
    }
    return sHostName;
}

// Calling above method:
string sDBHostName = ServerData.GetDBHost();
IPAddress[] ipadd = Dns.GetHostAddresses(sDBHostName); <--- returns 22.23.24.25

Is there a way of using 22.23.24.25 to get VM IPs?

NoBullMan
  • 2,032
  • 5
  • 40
  • 93

0 Answers0