How to use SQLConfigDataSource ODBC API FUNCTION

I want to use SQLConfigDataSource ODBC API function to
add a data source dynamically without calling the setup dialog box

please give me a complete example with C++ or VISUAL BASIC
adelchabbouhAsked:
Who is Participating?
 
tma050898Connect With a Mentor Commented:
Here's an example of doing that with an Access database.

CString strAddDsn;
strAddDsn.Format("DSN=%s~DBQ=%s~UID=\"Admin\"~PWD=\"\"~Fil=MS Access~Exclusive=True~Readonly=False~~",
strDsn, strPathToFile);

char szDsn[255];
strcpy(szDsn, strAddDsn);
for (signed int i = strlen(szDsn) - 1; i >= 0; i--)
{
 if (szDsn[i] == '~')
 {
  szDsn[i] = 0x00;
 }
}

RETCODE rc = ::SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", szDsn);

0
 
adelchabbouhAuthor Commented:
This is for tma
 think you for our answer
It's my first time programing in VC++
can you give me please witch library Ihave to import
and witch .H files Ihave to include

think you.
0
All Courses

From novice to tech pro — start learning today.