Solved

List of Data Source Names

Posted on 2000-04-14
14
245 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

867 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

23 Experts available now in Live!

Get 1:1 Help Now