Solved

List of Data Source Names

Posted on 2000-04-14
14
260 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

830 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