In VC++, I used ODBC to connect Database with the following string:
SQLDriverConnect (sqlconnectionhandle,
NULL,
L"Driver={SQL Server};Server=serverIP, 1433;Database=DBName;Uid=aaa;Pwd=bbb;",
SQL_NTS,
retconstring,
1024,
NULL,
SQL_DRIVER_NOPROMPT))
my question is how to input the userName and userPw generically withou hardcoding.
Here, L means Unicode.
eg: (this example doesnt work)
SQLWCHAR userName = L"aaa";
SQLWCHAR userPw = L"bbb";
SQLWCHAR connString = L"Driver={SQL Server};Server=serverIP, 1433;Database=DBName;Uid=" + userName + ";Pwd=" + userPw + ";",
Here is an example for concat strings:(works!)
wchar_t* subString = L" currentDate = '2013-01-04' ";
SQLWCHAR queryString[] = L"select * from Table1 WHERE ";
wcscat_s(queryString, subString );
L”stringName” means this is Unicode string, using SQLDriverConnectA can solve the problem.
eg: