Solved

List of Data Source Names

Posted on 2000-04-14
14
252 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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 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.

803 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