两个关于ADO操作数据的问题,很着急!!!!
try
{
HRESULT hr;
_ConnectionPtr m_dbConn;
_CommandPtr m_pCommand;
hr = m_dbConn.CreateInstance(_uuidof(Connection));
hr = m_dbConn->Open((_bstr_t)m_strConn, "", "", -1);
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_dbConn; // ½«¿âÁ¬½Ó¸³ÓÚËü
while(g_pSQLList->GetSize() > 0)
{
SQLStruct *pSql = g_pSQLList->GetAt(0);
try
{
m_pCommand->CommandText = pSql->szSql ;
m_pCommand->Execute(NULL,NULL, adCmdText);
}
catch(_com_error &e)
{
CString strLog;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
#if _DEBUG
TRACE("Error\n");
TRACE("Code = %08lx\n", e.Error());
TRACE("Code meaning = %s\n", e.ErrorMessage());
TRACE("Source = %s\n", (LPCSTR) bstrSource);
TRACE("Description = %s\n", (LPCSTR) bstrDescription);
#endif
strLog = pSql->szSql;
strLog = "OnThreadWork Function "执行错误......" + strLog + "\n " + (LPCSTR)bstrDescription;
m_errProc.WriteErrorLog(strLog);
}
#if _DEBUG
TRACE("Excute Sql........ " + pSql->szSql + "\n");
#endif
g_pSQLList->RemoveAt(0);
delete pSql;
pSql = NULL;
}
m_pCommand.Release();
m_dbConn->Close();
m_dbConn.Release();
}
catch(_com_error &e)
{
CString strLog;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
#if _DEBUG
TRACE("Error\n");
TRACE("Code = %08lx\n", e.Error());
TRACE("Code meaning = %s\n", e.ErrorMessage());
TRACE("Source = %s\n", (LPCSTR) bstrSource);
TRACE("Description = %s\n", (LPCSTR) bstrDescription);
#endif
strLog = (LPCSTR)bstrDescription;
strLog = "OnThreadWork Function “发送错误......" + strLog;
m_errProc.WriteErrorLog(strLog);
}
catch(CException &e)
{
char szError[2048];
e.GetErrorMessage(szError, 2048);
m_errProc.WriteErrorLog(szError);
e.Delete();
}
catch(...)
{
LPVOID lpMsgBuf;
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL ))
{
// Display the string.
CString strLog;
strLog = (LPCTSTR)lpMsgBuf;
strLog = "OnThreadWork Function "发生错误........." + strLog;
m_errProc.WriteErrorLog(strLog);
// Free the buffer.
LocalFree( lpMsgBuf );
}
}
以上代码在我本机执行没有任何问题。
编译版本放在服务器上,每次都是执行到
strLog = "OnThreadWork Function “发送错误......" + strLog;
也就是说在打开数据库连接对象的时候发生错误,但是错误信息为空,没有内容。
我本机与服务器都是Windows 2000。
请问如何解决这个问题??
另外一个问题是为什么利用 SystemTimeToVariantTime 函数将日期转换为双精度之后,再将这个值赋值到Sql语句中,在写入数据库时,日期都会比当前时间晚正好两天。