这个错误是我去掉try catch后显示的。当我又加上入下代码时却显示操作成功完成的error对话框 try
{
m_pConnection->ConnectionTimeout = 8;
//连接SQL SERVER
m_pConnection->Open("Driver=SQL Server;Database=test;Server=127.0.0.1;UID=ljj;PWD=1234;","","",adModeUnknown);
}
catch(_com_error e)///捕捉异常
{
// AfxMessageBox("数据库连接失败!");//以下是我自己加的,我想看看为什么会连接失败。
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM | 
                  FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  (LPTSTR) &lpMsgBuf,0,NULL );
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
return FALSE;

/**********************************************/