Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Auto-discover Oracle TNS service names with COSidHelper class

0.00/5 (No votes)
5 Sep 2003 1  
An article on how to discover Oracle TNS service names.

Sample Image - OSidList.jpg

Introduction

This article introduces a class which automatically constructs Oracle TNS service names defined on a local machine.

Background

I always wonder how to find out how many Oracle instances are defined programmatically. Using SQL*Plus, one has to type in the Oracle instance name. In some cases, because we may have a lot of databases, we often make mistakes. One day I decided to write something to automatically discover all the Oracle instances defined on the local machine. So here comes COSidHelper class.

Using the code

This code is very easy to use, you add SidHelper.h and SidHelper.cpp into your project, then when you need to display Oracle TNS service names, simply construct an instance of this class like this:

COSidHelper osidHelper;
for( int nIndex =0; nIndex < osidHelper.m_strArray.GetSize(); nIndex++ )
{
    // ...

}

For test purposes, I also put in a Display() method there.

Points of interest

  1. Check directory existence. In older Oracle client installs, tnsnames.ora is under net80, in newer version, it is under network directory.
  2. RegistryKey operation.
  3. Parser for Oracle tnsnames.ora file structure.

History

I wrote this class long time ago for a software called PowerQuery). Today finally got time to share it with CodeProject community. You can use this class for free.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here