0

How can I enumerate Oracle Database names in C#?

I am able to query all available databases for a MSSQL connection string:

using (var con = new SqlConnection("Password=TestPassword;User ID=TestUser;Data Source=localhost"))
{
    con.Open();

    return con.GetSchema("Databases")
                .Rows.Cast<DataRow>()
                .Select(row => row.Field<string>("database_name"))
                .ToList();
}
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • 4
    `Every oracle db instance has only One database`, in this case it's completely different from MS SQL Server – void Jan 29 '15 at 08:44
  • Some useful reading https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1631683800346891854 – Lalit Kumar B Jan 29 '15 at 08:56

1 Answers1

2

If you are using ODP.NET, you can use the OracleDataSourceEnumerator to list the TNS entries. See the documentation here.

If not then you'll have to parse the tnsnames.ora yourself.

Community
  • 1
  • 1
Stuart Grassie
  • 3,043
  • 1
  • 27
  • 36