::CoInitialize(NULL);
_ConnectionPtr m_pCon;
_RecordsetPtr m_pRs;
m_pCon.CreateInstance(__uuidof(Connection));
m_pCon->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=考生考试系统.mdb","","",adModeUnknown);
m_pRs.CreateInstance(__uuidof(Recordset));我是用以上ado方法与数据库相连接的。由于多个对话框都使用同一个数据库,所以我把m_pCon定义成全局变量了,只在进入程序的时候连接,然后离开程序的时候再关闭。但是,就下面这些操作,前几次能用,但操作了几次以后,就不知道为什么产生错误,错误提示是:abnormal program termination.为什么?是不是哪里还需要怎么设置?还是别的什么原因。
m_pRs->AddNew();
m_pRs->PutCollect("Extra",_variant_t(m_beizhu));
m_pRs->Update();急啊,敬请高手指点,不胜感谢……

解决方案 »

  1.   

    注意捕捉异常,尤其是_com_error, 这样就能知道是什么错,而不是 abnormal pro...示例   try
       {
          ADODB::_ConnectionPtr  Conn1 = NULL;
          Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
          
          // To see each of the catch blocks work, comment out all but
          // one of the following 4 lines, each of which throws an
          // exception.      // Bogus DataSource Name, raises _com_error
          Conn1->Open( L"", L"", L"", -1 );      // Explicitly raise MFC Exception
          AfxThrowMemoryException();      // Explicitly raise SEH Exception
          RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);      // Explicitly raise exception of a type not caught below
          // i.e. to the catch handlers, an "Unknown exception"
          throw 0L;   // Raises exception of type long
       }
       // Catch Blocks -- All of which are a subset of the 
       //                 Exception Handling demonstrated in LOG.CPP
       //                 in the C++ Rosetta Stone Samples
       catch( CException *e )
       {
          CString         strName;  
          CRuntimeClass   *pClass = e->GetRuntimeClass();      printf( "MFC Exception(%s) thrown\n",
                (LPCTSTR) pClass->m_lpszClassName );
       }
       catch( _com_error &e )
       {
          printf( "#import encountered failed HRESULT\n" );
          printf( "\tCode = %08lx\n",      e.Error());
       }
       catch( SEH_Exception &e )
       {
          printf( "Win32 Structured Exception Raised\n" );
          printf( "\t Error Code %08lx\n", e.getSeHNumber() );
       }
       catch(...)
       {
          printf( "Caught an exception of unknown type\n" );
       }
      

  2.   

    很有可能m_beizhu为空注意判断
      

  3.   

    能不能给我贴出ado访问数据库的标准的格式?基本的我都知道,但不知怎地会出现一些莫名其妙的错误,可能是使用的还不规范吧。谢谢先。
      

  4.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=11832
      

  5.   

    错误是_com_error,请问要如何才能解决呢?