我目前正在使用Phoenix ODBC驱动程序。我只能与某个用户访问凤凰。当我对两个用户使用SQLDriverConnect时,它可以工作。但是,如果我调用ImpersonateLoggedOnUser,则SQLDriverConnect无法找到DSN。它给了我以下错误。
[Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序。
代码如下。你能帮我吗?
//login with user
DWORD dwSize;
HANDLE hToken;
LPVOID lpvEnv;
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
WCHAR szUserProfile[256] = L"";
TCHAR * tstrUserName = L"USERNAME" ;
TCHAR * tstrPassword = L"PASSWORD" ;
si.cb = sizeof(STARTUPINFO);
if (!LogonUser(
tstrUserName,
NULL,
tstrPassword,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&hToken
)
)
{
auto value = GetLastError();
throw "Cannot Login With ANOTHER USER";
}
ImpersonateLoggedOnUser(hToken);
w_char *connectionString = L"DSN=Phoenix";
SQL_ENVIRONMENT env;
SQL_DBC_HANDLE dbcHandle;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env) == SQL_ERROR)
{
throw;
}
// Register this as an application that expects 3.x behavior,
// you must register something if you use AllocHandle
SQLSetEnvAttr(env,
SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3,
0);
//allocate a connection
RETCODE ret = 0;
ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &dbcHandle);
if(ret == SQL_ERROR || dbcHandle == nullptr )
throw;
//connect with driver to odbc
ret = SQLDriverConnect( dbcHandle,
nullptr,
connectionString,
SQL_NTS,
nullptr,
0,
nullptr,
SQL_DRIVER_NOPROMPT
);
答案 0 :(得分:0)
你的代码看起来都很明智。但是,在odbc中创建数据源时,首先检查简单的东西......