Exemplo n.º 1
0
DWORD CNHSQLServerDBO::CloseDB(_ConnectionPtr &pConnection)
{
    //assert(NULL != pConnection);

    DWORD dwReturn(0x00);

    try
    {
        //关闭连接
        if (NULL!=pConnection && adStateClosed!=pConnection->State)
        {
            pConnection->Close();
        }
        if (NULL != pConnection)
        {
            pConnection.Release();
            pConnection = NULL;
        }
    }
    catch (_com_error &e)
    {
//#ifdef _DEBUG
        // 输出错误信息到输出窗口
        OutputDebugStringW(L"\t");
        OutputDebugStringW(L"CNHSQLServerDBO::CloseDB发生错误。");
        OutputDebugStringW(L"\n");
        // 输出错误信息到日志文件
        if (0 != wcscmp(m_wchLogFilePath, L""))
        {
            // 当日志文件路径不为空时,写日志
            CNHLogAPI::WriteLogEx(m_wchLogFilePath, LOG_ERR, L"NHSQLServerDBO", L"CNHSQLServerDBO::CloseDB发生错误。");
        }
        OutputDBErrMsg(e);
//#endif
        dwReturn = 0x01;
    }

    // 卸载COM组件
    CoUninitialize();

    return dwReturn;
}