Click here to Skip to main content
15,898,980 members
Articles / Desktop Programming / MFC
Article

Auto-discover Oracle TNS service names with COSidHelper class

Rate me:
Please Sign up or sign in to vote.
4.20/5 (11 votes)
5 Sep 20031 min read 71.3K   948   22   9
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


Written By
Web Developer
United States United States
LI is a architect of several database-centric tools and technologies. He has been programming since 1995. He is a Microsoft Certified Solution Developer (MCSD), MCSD.NET, SCJP, SCJD and OCDBA.

His programming experience includes C/C++, C#, MFC, ASP, VB and Perl. He has worked on Solaris, AIX, HPUX and various Windows, and found Windows is the easiest one to work with.

He has over 8 years of database experiences in Oracle, SQL Server, DB2 and other DBMS.

LI co-founded AgileInfoSoftware LLC (http://www.agileinfollc.com) in 2003. He is responsible for the overall vision and development strategy of the company.

Comments and Discussions

 
Questionfix oracle11g、oracle12g and 64bit os Pin
XiaoQing Li15-Jul-16 16:42
XiaoQing Li15-Jul-16 16:42 
GeneralMy vote of 4 Pin
Laurent26-Aug-13 2:41
Laurent26-Aug-13 2:41 
Generalhelp please. Pin
M_Nuaimi26-Apr-06 15:14
M_Nuaimi26-Apr-06 15:14 
Hi.
I’m trying to develop an application that operates on the oracle database using (ODBC) CDatabase & CRecordset. But the application can't show the record (NUMBER) type correctly and it show instead some strange numbers in the edit contrl. -19841 something like this.

// here's an example of the code.
char str[255];
int index=0;
CDBVariant var;
record.GetFieldValue(index,var);
wsprintf(str,"%d",var.m_iVal);
EditCtrl->SetWindowText(str);

May you tell me please what I have to do to convert the number and show it correctly?

I'm using VC++ 6.0 & Oracle 9i (9.2.0.1.0)

Best regards.

GeneralOracle SID is showning NO records Pin
lovix6-May-05 6:35
lovix6-May-05 6:35 
GeneralRe: Oracle SID is showning NO records Pin
ChasCurry4-Aug-05 5:37
ChasCurry4-Aug-05 5:37 
GeneralRe: Oracle SID is showning NO records Pin
MachhaPuchhre20-Dec-05 18:11
MachhaPuchhre20-Dec-05 18:11 
QuestionWhat is it? Pin
Uwe Keim7-Sep-03 3:31
sitebuilderUwe Keim7-Sep-03 3:31 
AnswerRe: What is it? Pin
Uwe Keim7-Sep-03 8:12
sitebuilderUwe Keim7-Sep-03 8:12 
GeneralRe: What is it? Pin
Sebastien Lorion7-Sep-03 9:58
Sebastien Lorion7-Sep-03 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.