CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Location
    San Diego, CA
    Posts
    1

    Getting a list of DSN's?

    How can I display a list of User DSN's in my program? I want to mimic the list you get under 'ODBC Data Sources' on the control panel. Is there an MFC object for this? Do I have to look in the registry? Thanks for any help.


  2. #2
    Join Date
    May 1999
    Location
    Wisconsin, USA
    Posts
    953

    Re: Getting a list of DSN's?

    Use the ODBC API like this:



    HENV hEnv;
    UCHAR tmpDSN[256];
    SWORD tmpDSNLen = 255;
    SWORD ResultLen;
    UCHAR tmpDriver[256];
    SWORD tmpDriverLen = 255;
    SWORD ResultDescLen;
    RETCODE ReturnCode = SQL_SUCCESS;

    ReturnCode = ::SQLAllocEnv(&hEnv);
    if (SQL_SUCCESS == ReturnCode)
    {
    ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_FIRST, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);

    while (SQL_SUCCESS == ReturnCode)
    {
    ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_NEXT, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
    }
    }

    ::SQLFreeEnv(hEnv);





    This will return all the DSNs you'll have to do something about listing only User DSNs.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured