Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

List of Data Source Names

Posted on 2000-04-14
14
Medium Priority
?
293 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
jbodom earned 165 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
 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

916 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