Solved

List of Data Source Names

Posted on 2000-04-14
14
234 Views
Last Modified: 2010-04-10
Hi
I am programming in Visual C++ 6.0 and I would like to provide a drop-down list of ODBC DSNs currently set up on the user's system.

Help is appreciated!
Shaun
0
Comment
Question by:Mossy
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2715735
Hi
check this functon it returns U only Excel driver if present.
U can Use
SQLGetInstalledDrivers(....) function to get all the installed drivers
for this U have to include odbcinst.h file..

CString CDao1TryView::GetExcelDriver()
{
    char szBuf[2001];
    WORD cbBufMax = 2000;
    WORD cbBufOut;
    char *pszBuf = szBuf;
    CString sDriver;

    // Get the names of the installed drivers ("odbcinst.h" has to be included )
   if(!SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut))
        return "";
     
    // Search for the driver...
//U CAN CHANGE THIS TO ALL PRESENT
    do
    {
        if( strstr( pszBuf, "Excel" ) != 0 )
        {
            // Found !
            sDriver = CString( pszBuf );
            break;
        }
        pszBuf = strchr( pszBuf, '\0' ) + 1;
    }
    while( pszBuf[1] != '\0' );

    return sDriver;
}

Hope this helps
inpras
0
 

Author Comment

by:Mossy
ID: 2715848
Adjusted points from 50 to 55
0
 

Author Comment

by:Mossy
ID: 2715849
This is great, thanks inpras, however what I am really after is the ODBC Data Source Names.
0
 
LVL 1

Accepted Solution

by:
jbodom earned 55 total points
ID: 2715960
The 16-bit ODBC components use INI files to store information on configured datasources (ODBC.INI) and installed drivers (ODBCINST.INI).

The 32-bit ODBC components use the registry. System datasource information and installed driver information is stored in HKEY_LOCAL_MACHINE\SOFTWARE\ ODBC\ in ODBC.INI and ODBCINST.INI, respectively. Non-System datasources are stored in HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI

All you have to do is write the code to get the info
0
 

Author Comment

by:Mossy
ID: 2715989
Thanks jb
Now all I have to do is find the code to read the registry!
0
 
LVL 32

Expert Comment

by:jhance
ID: 2716413
RegOpenKeyEx(), RegQueryValueEx(), RegCloseKey(), etc...
0
 
LVL 2

Expert Comment

by:bratt030900
ID: 2716546
Here is MSDN's Registry Functions:
http://msdn.microsoft.com/library/psdk/winbase/regapi_59mb.htm

I looked around on my machine and found some code examples in:
MFC\SRC\VIEWSCRL.CPP (around line 90)
MFC\SRC\APPUI3.CPP (around line 140) code for GetProfileString
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Expert Comment

by:GlennDean
ID: 2717140
To see some code that opens and queries the value of Registry entries, the code for CWinApp::GetProfileInt, CWinApp::GetSectionKey, and CWinApp::GetAppRegistryKey shows you everything you want to do.
   Glenn
0
 

Author Comment

by:Mossy
ID: 2722616
Thanks for your help everyone,
very much appreciated.
It is not easy to decide who gets the points because everyone helped with the answer in some way, but I have decided the most significant contribution was from jdobom, so he (or she) wins the points.

To everyone else, please accept my thanks.

Shaun

0
 

Author Comment

by:Mossy
ID: 2722618
Thanks jbodom your info really helped.
0
 
LVL 1

Expert Comment

by:jbodom
ID: 2723966
Glad i could help
0
 
LVL 4

Expert Comment

by:inpras
ID: 2725412
SQLGetInstalledDrivers
will do everything I donno why U rejected will U give some reasons for that Pl?
0
 

Author Comment

by:Mossy
ID: 2725705
Sure inpras.

My reason is that it is my understanding that SQLGetInstalledDrivers will only tell me the installed ODBC drivers.  This is not what I want to know.

I want to know the Data Source Names (DSN) that are currently set up.

I still do really appreciate your input.

Mossy
0
 
LVL 4

Expert Comment

by:inpras
ID: 2727199
I am sorry I misread UR question U can use SQLDataSource(...) for that just an input
Thanks a lot
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now