I don't know for sure why the access violation occurs but it is probably due to the
UserName
and
Authentication
parameters. When those are
NULL
, you should also pass zero instead of
SQL_NTS
for the length:
c = SQLConnect(ConHandle, (SQLWCHAR*)L"dailyworkbook", SQL_NTS, NULL, 0, NULL, 0);
or pass empty strings which may use
SQL_NTS
or zero
c = SQLConnect(ConHandle, (SQLWCHAR*)L"dailyworkbook", SQL_NTS, (SQLWCHAR*)L"", SQL_NTS, (SQLWCHAR*)L"", SQL_NTS);
If you have to use char or wide strings depends on your project settings. The above assumes that you have a Unicode project.
I can also only guess why you did not get the access violation with the first call but I think this is a potential explanation:
When having a Unicode build and passing a char string, the connect will fail because the server can not be found and the function returns before using the additional parameters.