CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

runtime error怎么解决

楼主schuyler(乐开)2003-12-03 08:33:34 在 VC/MFC / 基础类 提问

我写了一个程序,用到了数据库、socket、线程,程序运行一段时间后(时间不定,有时一下午,有是两三天)会出现runtime   error,点确定后退出,这个问题很严重。请问各位遇到过么?怎么解决?  
  我曾经看过用try   。。。except忽略的说明,不过我在数据库部分使用了try。。。catch,好像try之间不能嵌套,请各位指教。 问题点数:0、回复次数:14Top

1 楼flyelf(空谷清音)回复于 2003-12-03 09:17:08 得分 0

这是一个事后调试的情况,可以使用windows的Dr.Watson日志文件,能比较快速找到问题所在Top

2 楼FlyYang(++X++)回复于 2003-12-03 09:29:37 得分 0

先用win2k的任务管理器看你的程序有没有资源泄漏  
  内存,句柄,GDI等资源  
   
  ---------  
      ++C++  
  ---------  
  Top

3 楼schuyler(乐开)回复于 2003-12-03 10:06:45 得分 0

to   flyelf:  
        windows的dr.watson日志文件是不是就是事件查看器中查看的文件?  
  还有Try   except怎么用啊Top

4 楼bohut(●伯虎● )回复于 2003-12-03 10:08:22 得分 0

这个问题要首先想到是不是内存泄漏Top

5 楼E17(守护星)回复于 2003-12-03 10:12:18 得分 0

多半   给我的感觉上   线程的问题Top

6 楼lygfqy(风清扬)回复于 2003-12-03 10:14:14 得分 0

比较可能的情况是数据库释放不是太正常的缘故Top

7 楼schuyler(乐开)回复于 2003-12-03 10:21:54 得分 0

各位,不如这样,我就献丑了,我吧这个东东贴出来,大家多指教啊Top

8 楼jszj(老板说mis部不是赚钱的部门...)回复于 2003-12-03 10:25:35 得分 0

1.檢查一個線程用完之後是否及時釋放  
  2。檢查數據庫是否會有問題出現而使客戶機不能連接而你的程序沒有認真的檢查這種情況的發生  
  3。動態變量(動態數組)你是否每次都在用完之後釋放掉了  
  4。檢查你程序中定義的那些不常使用的變量而當你寫程序時而忘記了對他的認真檢查而出錯的可能性,即不要漏掉了不常使用的變量的檢查  
  5。可能查看一下系統日志看是否有系統出現問題的可能性Top

9 楼schuyler(乐开)回复于 2003-12-03 10:25:49 得分 0

#include   "stdafx.h"  
  #include   "ShortMsg.h"  
  #include   "ShortMsgDlg.h"  
   
  #include   "NkiDll/NkiDll.h"  
   
  //   初始化网络  
  #include   <winsock2.h>  
  #include   "info.h"  
   
  #ifdef   _DEBUG  
  #define   new   DEBUG_NEW  
  #undef   THIS_FILE  
  static   char   THIS_FILE[]   =   __FILE__;  
  #endif  
   
  //   *******   Define   Global   var     *********    
  //  
  const   int iPort =   5151;  
  const   int lPort =   5150;  
  BOOL g_DCheck =   false;  
   
  int   SendMsg(const   alarmInfo&   info);  
  //   ***********   InitSocket   **************  
  //  
  int   InitSocket()  
  {  
  WSADATA wsd;  
   
  //   初始化网络  
  if   (   WSAStartup(   MAKEWORD(2,   2),   &wsd)   !=   0)  
  {  
  AfxMessageBox("网络初始化失败!");  
  }  
   
  return   0;  
  }  
   
  //   **************   InitDataBase   **********  
  //  
  int   InitDbConn(_bstr_t   &   conn   )  
  {  
  ::CoInitialize(NULL);  
  IRiseAccObjPtr   RiseObj;  
  HRESULT   hr;  
  hr=RiseObj.CreateInstance(__uuidof(RiseAccObj));  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("连接串出错!");  
  ::CoUninitialize();  
  return   false;  
  }  
   
  RiseObj->GetSidData("RiseOffice");  
  conn=RiseObj->GetconnStr();  
  ::CoUninitialize();  
  return   0;  
  }  
   
  //   ***********   GetlocalIp   **************  
  //  
  int   GetlocalIp(char   m_I[16])  
  {  
  //   定义、初始化变量  
  char name[255];      
  PHOSTENT hostinfo;  
  char   * m_Ip =(char   *)malloc(sizeof(char)   *   16);  
   
  //   取得ip地址  
  if(   gethostname   (   name,   sizeof(name))   ==   0)  
  {  
  if((hostinfo   =   gethostbyname(name))   !=   NULL)  
  {  
  m_Ip   =   inet_ntoa   (*(struct   in_addr   *)*hostinfo->h_addr_list);  
  }  
  }  
   
  strcpy(m_I,   m_Ip); //   设置输出变量  
  free(m_Ip);  
  m_Ip   =   NULL;  
  return   0;  
  }  
   
   
  //   ************   UserRegister   ***************  
  //  
  int   UserRegister(const   ClientInfo   &   uRegInfo)  
  {  
  ::CoInitialize(NULL);  
   
  _ConnectionPtr d_Connection;  
  _RecordsetPtr d_Recordset;  
  _variant_t RecordsAffected;  
  _bstr_t connStr;  
  _bstr_t query;  
  HRESULT hr;  
  char rsql[128];  
  char csql[128];  
  alarmInfo aInfo;  
   
  InitDbConn(connStr);  
  memset(&aInfo,   '\0',   sizeof(aInfo));  
  memset(csql,   '\0',   128);  
  strcpy(csql,   "Select   *   from   RiseManager..EmployeeDefine   where   Email   ='");  
  strcat(csql,   uRegInfo.userName);  
  strcat(csql,   "'   and   privateKey='");  
  strcat(csql,   uRegInfo.passWord);  
  strcat(csql,   "'");  
  query=csql;  
   
  try  
  {  
  hr=d_Recordset.CreateInstance   (__uuidof(Recordset));  
  if(FAILED(hr))  
  {  
  AfxMessageBox("创建数据集错误!");  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr=d_Recordset->Open(query,connStr,adOpenDynamic,adLockOptimistic,adCmdText);  
  if(FAILED(hr))  
  {  
  AfxMessageBox("打开数据集错误");  
  d_Recordset->Close();  
  d_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  if   (d_Recordset->adoEOF)  
  {  
  aInfo.aIType   =   A_USERINFOERROR;  
  strcpy(aInfo.userIp,   uRegInfo.localIp);    
  SendMsg(aInfo);  
  d_Recordset->Close();  
  d_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  d_Recordset->Close();  
  d_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  memset(rsql,   '\0',   128);  
  strcpy(rsql,   "UserRegist   @UserName='");  
  strcat(rsql,   uRegInfo.userName);  
  strcat(rsql,   "',   @UserIp='");  
  strcat(rsql,   uRegInfo.localIp);  
  strcat(rsql,   "'");  
   
  query=rsql;  
  try  
  {  
  hr=d_Connection.CreateInstance   (__uuidof(Connection));  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("创建连接错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Open(connStr,   "",   "",   adModeUnknown);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("打开连接错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Execute(query,   &RecordsAffected,   adCmdText);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("执行错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  d_Recordset->Close();  
  d_Recordset   =   NULL;  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   0;  
  }  
  Top

10 楼schuyler(乐开)回复于 2003-12-03 10:26:21 得分 0

//   **************   UserQuit   ****************  
  //  
  int   UserQuit(const   ClientInfo&   info)  
  {  
  ::CoInitialize(NULL);  
   
  _ConnectionPtr d_Connection;  
  _variant_t RecordsAffected;  
  _bstr_t connStr;  
  HRESULT hr;  
  char rsql[128];  
   
  InitDbConn(connStr);  
  memset(rsql,   '\0',   128);  
  strcpy(rsql,   "UserQuit   @UserName='");  
  strcat(rsql,   info.userName);  
  strcat(rsql,   "',   @UserIp='");  
  strcat(rsql,   info.localIp);  
  strcat(rsql,   "'");  
   
  try  
  {  
  hr=d_Connection.CreateInstance   (__uuidof(Connection));  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("创建连接错误!");  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Open(connStr,   "",   "",   adModeUnknown);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("打开连接错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Execute(rsql,   &RecordsAffected,   adCmdText);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("执行错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
   
  return   0;  
  }  
   
   
  //   ************   UserReceive   ****************  
  //  
  int   UserReceive(const   ClientInfo&   info)  
  {  
  ::CoInitialize(NULL);  
   
  _ConnectionPtr d_Connection;  
  _variant_t RecordsAffected;  
  _bstr_t connStr;  
  _bstr_t query;  
  HRESULT hr;  
  char rsql[128];  
  char temp[6];  
   
  InitDbConn(connStr);  
  memset(rsql,   '\0',   128);  
   
  strcpy(rsql,   "UserReceive   @id='");  
  strcat(rsql,   itoa(info.task.workflowid,   temp,   10));  
  strcat(rsql,   "',   @it='");  
  strcat(rsql,   itoa(info.task.workflowinstance,   temp,   10));  
  strcat(rsql,   "',   @idx='");  
  strcat(rsql,   info.task.workflowinstanceidx   );  
  strcat(rsql,   "'");  
  query=rsql;  
  try  
  {  
  hr=d_Connection.CreateInstance   (__uuidof(Connection));  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("创建连接错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Open(connStr,   "",   "",   adModeUnknown);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("打开连接错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr   =   d_Connection->Execute(query,   &RecordsAffected,   adCmdText);  
  if   (FAILED(hr))  
  {  
  AfxMessageBox("执行错误!");  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  d_Connection->Close();  
  d_Connection   =   NULL;  
  ::CoUninitialize();  
   
  return   0;  
  }  
   
   
  //   ************   ProcessData   ****************  
  //  
  int   ProcessData(char   recv[])  
  {  
  ClientInfo*   uInfo   =   (ClientInfo   *)recv;  
   
  if   (uInfo   !=   NULL)  
  {  
  switch   (uInfo->infoType)  
  {  
  case   T_REGISTER:  
  UserRegister(*uInfo);  
  break;  
  case   T_RESPONSE:  
  break;  
  case   T_SEND:  
  UserReceive(*uInfo);  
  break;  
  case   T_QUIT:  
  UserQuit(*uInfo);  
  break;  
  default:  
  break;  
  }  
  }  
   
  return   0;  
  }  
   
   
  //   ************   ListenThread   ***************  
  //  
   
  DWORD   WINAPI   ListenThread(LPVOID   lpParam)  
  {  
  WSADATA wsd;  
  SOCKET listen;  
  SOCKADDR_IN   local;  
  SOCKADDR_IN   remote;  
  char   * recvbuf =   NULL;  
  char szip[16];  
  int ret;  
  int dwSenderSize =   sizeof(remote);  
  int dwLength =   1024;  
   
  recvbuf =   new   char[1024];  
  memset(recvbuf,   '\0',   1024);  
  GetlocalIp(szip);  
   
  if   (WSAStartup(MAKEWORD(2,   2),   &wsd)   !=   0)  
  {  
  AfxMessageBox("网络初始化失败!");  
  return   -1;  
  }  
  listen   =   socket(AF_INET,   SOCK_DGRAM,   0);  
   
  local.sin_family =   AF_INET;  
  local.sin_port =   htons((short)iPort);  
  local.sin_addr.s_addr =   inet_addr(szip);  
   
  if   (bind(listen,   (SOCKADDR   *)&local,   sizeof(local))   ==   SOCKET_ERROR)  
  {  
  AfxMessageBox("绑定失败!");;  
  }  
  while   (1)  
  {  
  ret   =   recvfrom(listen,   recvbuf,   dwLength,   0,   (SOCKADDR   *)&remote,   &dwSenderSize);  
  if   (ret   >   0)  
  {  
  recvbuf[ret]   ='\0';  
  }  
   
  ProcessData(recvbuf);  
  Sleep(100);  
  }  
   
  return   0;  
  }  
   
   
  //   ***************   OnLine   ******************  
  //  
  int   OnLine(alarmInfo   *   info)  
  {  
  __try  
  {  
   
  ::CoInitialize(NULL);  
  _RecordsetPtr m_Recordset;  
  _bstr_t query;  
  _bstr_t connStr;  
  HRESULT hr;  
  char str[128];  
   
   
  strcpy(str,"Select   *   from   RiseOffice..OnLineUser   where   uname='");  
  strcat(str,info->userName);  
  strcat(str,"'");  
  query=str;  
  InitDbConn(connStr);  
  try  
  {  
  hr=m_Recordset.CreateInstance   (__uuidof(Recordset));  
  if(FAILED(hr))  
  {  
  AfxMessageBox("创建数据集错误!");  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr=m_Recordset->Open(query,connStr,adOpenDynamic,adLockOptimistic,adCmdText);  
  if(FAILED(hr))  
  {  
  AfxMessageBox("打开数据集错误");  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  if   (!(m_Recordset->adoEOF))  
  {  
  strcpy(info->userIp,   (char*)_bstr_t(m_Recordset->GetCollect("ip")));    
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   1;  
  }  
   
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  }  
  __except(EXCEPTION_CONTINUE_EXECUTION)  
  {}  
  return   0;  
  }  
   
   
  //   ***************   SendMessage   *****************  
  //  
  int   SendMsg(const   alarmInfo   &   info)  
  {  
  //   定义变量  
  SOCKET sender;  
  struct   sockaddr_in remote;  
  int ret;  
   
  remote.sin_family =   AF_INET;  
  remote.sin_port =   htons(lPort);  
  remote.sin_addr.s_addr =   inet_addr(info.userIp);  
   
  sender   =   socket(AF_INET,   SOCK_DGRAM,   0);  
   
  ret =   sendto(sender,   (char*)&info,   sizeof(info),   0,   (SOCKADDR   *)&remote,   sizeof(remote));  
  if   (ret   ==   SOCKET_ERROR)  
  {  
  AfxMessageBox("RegistUser->sender->sendto");  
  }  
   
  closesocket(sender);  
   
  return   0;  
  }  
  Top

11 楼schuyler(乐开)回复于 2003-12-03 10:30:23 得分 0

//   ***************   GetRecorder   *****************  
  //  
   
  UINT   GetRecorder(LPVOID   m_hWnd_Dlg)  
  {  
   
  if(!g_DCheck)  
  return   0;  
  HWND   m_hWndDlg=HWND(m_hWnd_Dlg);  
  ::KillTimer(m_hWndDlg,1);  
  ::CoInitialize(NULL);  
   
  HRESULT hr;  
  _RecordsetPtr m_Recordset;  
  _bstr_t connStr;  
  _bstr_t query=_T("Select   *   From   RiseOffice..MobileMsg");  
   
  InitDbConn(connStr);  
   
  try  
  {  
  hr=m_Recordset.CreateInstance   (__uuidof(Recordset));  
  if(FAILED(hr))  
  {  
  AfxMessageBox("创建数据集错误!");  
  ::CoUninitialize();  
  return   -1;  
  }  
  hr=m_Recordset->Open(query,connStr,adOpenDynamic,adLockOptimistic,adCmdText);  
  if(FAILED(hr))  
  {  
  AfxMessageBox("打开数据集错误");  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
  }  
  catch   (_com_error   &   e)  
  {  
  AfxMessageBox(e.ErrorMessage   ());  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  ////////////////////////  
  int ret;  
  char szNo[32];  
  char szMsg[512];  
  alarmInfo aInfo;  
  try  
  {  
  while(!m_Recordset->adoEOF)  
  {  
  memset(&aInfo,'\0',sizeof(aInfo));  
  aInfo.aIType   =   A_DATA;  
  strcpy(aInfo.actionType,   (char*)_bstr_t(m_Recordset->GetCollect("动作名称")));  
  strcpy(aInfo.mobileNum,   (char*)_bstr_t(m_Recordset->GetCollect("Mobile")));  
  aInfo.status   =   atoi((char*)_bstr_t(m_Recordset->GetCollect("statue")));  
  strcpy(aInfo.taskType,   (char*)_bstr_t(m_Recordset->GetCollect("任务类型")));  
  strcpy(aInfo.userName,   (char*)_bstr_t(m_Recordset->GetCollect("name")));  
  strcpy(aInfo.wFIIdx,   (char*)_bstr_t(m_Recordset->GetCollect("Workflow_Instanceidx")));  
  aInfo.wFInstance   =   atoi((char*)_bstr_t(m_Recordset->GetCollect("Workflow_Instance")));  
  aInfo.workFlow   =   atoi((char*)_bstr_t(m_Recordset->GetCollect("WorkFlow_Id")));  
   
  ret   =   OnLine(&aInfo);  
  if   (ret   ==   0   ||   (ret   ==   1   &&   aInfo.status   <=   1))  
  {  
  if(g_DCheck)  
  {  
  strcpy(szNo,(char*)_bstr_t(m_Recordset->GetCollect("Mobile")));  
  strcpy(szMsg,"您好,现有一份《");  
  strcat(szMsg,(char*)_bstr_t(m_Recordset->GetCollect("任务类型")));  
  strcat(szMsg,"》需要您");  
  strcat(szMsg,(char*)_bstr_t(m_Recordset->GetCollect("动作名称")));  
  strcat(szMsg,"。请速办理为盼!");  
   
  if(int   lRec   =   Sms_Send(   szNo   ,   szMsg   ,   false   ,   false   ,   false   ))  
  {  
  //更新状态  
  m_Recordset->Fields->GetItem(_variant_t("statue"))->Value=_bstr_t("0");  
  }  
  //AfxMessageBox(szMsg);  
  }  
  else  
  {  
  break;  
  }  
  }  
   
  if   (ret   ==   1   &&   aInfo.status   >   1)  
  {  
  aInfo.status--;  
  m_Recordset->Fields->GetItem(_variant_t("statue"))->Value   =   _variant_t((short)aInfo.status);  
   
  SendMsg(aInfo);  
  }  
   
  Sleep(20);  
   
  m_Recordset->MoveNext();  
  }  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  }  
  catch(_com_error   *   e)  
  {  
  AfxMessageBox(e->ErrorMessage());  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  return   -1;  
  }  
   
  //////////////结束返回////////  
  m_Recordset->Close();  
  m_Recordset   =   NULL;  
  ::CoUninitialize();  
  if   (g_DCheck)  
  ::SetTimer(m_hWndDlg,1,10000,NULL);  
  return   0;  
  }Top

12 楼fhqiplj(霏霏鱼)回复于 2003-12-03 10:49:53 得分 0

为什么不自己处理一下日志呢?Top

13 楼schuyler(乐开)回复于 2003-12-03 11:23:33 得分 0

to   fhqiplj(水园MSN俱乐部理事)   (霏霏)   :    
        偶是新手,请指教,怎么处理日志,是在程序中生成日志文件?请给个思路好吗?  
   
  谢谢,  
        希望听到大家的批评声Top

14 楼schuyler(乐开)回复于 2003-12-04 08:41:25 得分 0

自己up一下吧,Top

相关问题

  • Runtime error 216 at 02A60B12 怎么解决?
  • Runtime error?
  • VC连接Acess出现Runtime Error是怎么回事?
  • pb runtime error
  • Runtime Error '731'????
  • Runtime Error; Overflow
  • runtime error 2147467259 (80004005)
  • 救命啊,runtime error??
  • 什么叫Runtime Error?
  • 在线等待,运行VC++程序,出现Runtime Error!提示,这是怎么回事?急》》》》》》》

关键词

  • 数据库
  • 文件
  • hr
  • 网络
  • riseobj
  • 初始化
  • 程序
  • 日志
  • 檢查
  • 查看

得分解答快速导航

  • 帖主:schuyler

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo