1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
//Link with MS - odbccp32.lib ; GNU MinGW - libodbccp32.a
#include <windows.h>
#include <stdio.h>
#include <odbcinst.h>
unsigned int iInstallerError()
{
DWORD pErr;
char szErrMsg[512];
WORD cbMsgBuffer=512;
WORD cbRet;
WORD wErrNum=1;
while(SQLInstallerError(wErrNum,&pErr,szErrMsg,cbMsgBuffer,&cbRet)!=SQL_NO_DATA)
{
printf("wErrNum = %d\t",wErrNum);
printf("szErrMsg = %s\n",szErrMsg);
wErrNum++;
};
return (unsigned int)pErr;
}
int main()
{
char szBuffer[512],szCreate[512];
strcpy(szCreate,"CREATE_DB="); //SQLConfigDataSource() just basically takes a few
GetCurrentDirectory(512,szBuffer); //parameters the most important of which is the
strcat(szCreate,szBuffer); //path and name of the database you want created
strcat(szCreate, "\\TestData.mdb"); //and it creates the file.
printf("%s\n",szCreate); // <!!!>
if(SQLConfigDataSource(0,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb, *.accdb)",szCreate))
printf("SQLConfigDataSource() returned TRUE!\n");
else
printf("iInstallerError() = %d\n",iInstallerError());
getchar();
return 0;
}
/*
Output:
========================================================
CREATE_DB=C:\Code\CodeBlks\ConfigDataSource\TestData.mdb
SQLConfigDataSource() returned TRUE!
*/
|