How to connect to database after using SQLConfigDataSource to create database
I use SQLConfigDataSource to create an access database-
BOOL CDatabase::Create(CHAR *fileName, CHAR *name, CHAR *username, CHAR *password)
{
CHAR driver[MAX_STATEMENT_LENGTH];
CHAR attributes[MAX_STATEMENT_LENGTH];
sprintf(driver, "Microsoft Access Driver (*.mdb)");
sprintf(attributes, "CREATE_DB=%s General\0", fileName);
if (!SQLConfigDataSource(NULL, ODBC_ADD_DSN, driver, attributes))
return FALSE;
which works ok. I then set the DSN name using-
sprintf(attributes, "DSN=%s\0DBQ=%s\0", name, fileName);
if (!SQLConfigDataSource(NULL, ODBC_ADD_DSN, driver, attributes))
return FALSE;
which also works fine (the DSN name appears in the Control Panel ODBC Sources.
My question is, how do i connect to the database without a username/password.
Reading on the internet, passing Uid=<whatever>\0 and pwd=<something>\0 into the SQLConfigDataSource fails.
i tried connecting with-
SQLConnect(hDbc, (SQLCHAR*) name, SQL_NTS, (SQLCHAR*) user, SQL_NTS, (SQLCHAR*) pwd, SQL_NTS);
(Where user = "Admin" and pwd="")
but this fails.
I need to know how to connect (to create a user) or how to create a user/pwd that i can then connect to?
Hope this makes sense.
Many thanks in advance,
DumbMonkey
EDIT -- NEVER MIND - i fixed it. the sprintf function will not copy the entire string if there are '\0's in it, so the whole string does not get copied. I can now use SQLConfigDataSource with UID and PWD variables and use the same in SQLConnect. Thanks anyways.

