Пример #1
0
/*========================================================================
Name:	取得最后发生的error msg.
==========================================================================*/
CString CDBAccess::GetLastErrorText()
{
	ASSERT(m_pConnection != NULL);
	CString strErrors = "";
	try
	{
		if (m_pConnection != NULL)
		{
			ErrorsPtr pErrors = m_pConnection->Errors;
			CString strError;
			for (long n = 0; n < pErrors->Count; n++)
			{
				ErrorPtr pError = pErrors->GetItem(n);
				strError.Format(_T("Description: %s\r\nState: %s, Native: %d, Source: %s\r\n"),
					(LPCTSTR)pError->Description,
					(LPCTSTR)pError->SQLState,
					pError->NativeError,
					(LPCTSTR)pError->Source);
				strErrors += strError;
			}
		}
		return strErrors;
	}
	catch (_com_error e)
	{
		TRACE(_T("Warning: GetLastError function error. error msg: %s; file: %s; row: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
		return strErrors;
	} 
	return strErrors;
}
Пример #2
0
CString CAdoCommand::GetLastError()
{
	ASSERT(m_pConnection != NULL);
	CString strError="";
	try
	{
		if (m_pConnection != NULL)
		{
			ErrorsPtr pErrors = m_pConnection->GetErrors();
			if (pErrors->Count > 0)
			{
				ErrorPtr pError = pErrors->GetItem((long)(pErrors->Count - 1));	
				strError.Format("%s",(LPCTSTR)pError->SQLState);
				return strError;
			}
		}
	}
	catch (_com_error e)
	{
		TRACE(_T("Warning: GetLastError 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
	}
	catch(...)
	{
	}
	return "获取错误信息时异常";
}
Пример #3
0
ErrorPtr CAdoConnection::GetError(long index)
{
	ASSERT(m_pConnection != NULL);
	try
	{
		if (m_pConnection != NULL)
		{
			ErrorsPtr pErrors =  m_pConnection->Errors;
			if (index >= 0 && index < pErrors->Count)
			{
				return pErrors->GetItem(_variant_t(index));
			}
		}
		return NULL;
	}
	catch (_com_error e)
	{
		TRACE(_T("Warning: GetError 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
		return NULL;
	} 
	return NULL;
}