BeginTrans为什么会出错?
if(m_pConnection->State)
{
try
{
m_pRecordset=m_pConnection->Execute((const char*)strSQL,&RecordsAffected,adCmdText);
}
catch(_com_error e)
{
  AfxMessageBox(e.ErrorMessage());///显示错误信息
  return ;

}
if(m_pRecordset->adoEOF==-1)
{
if(m_pRecordset)m_pRecordset->Close();
return ;
}
while(!(m_pRecordset->adoEOF))
{
..............
_RecordsetPtr rs;
.................
m_pConnection->BeginTrans();//单步调试到这里发生未知错误。
try
{
......
}
catch(_com_error e)
{
m_pConnection->RollbackTrans();
AfxMessageBox(e.ErrorMessage());///显示错误信息
return ;
}
m_pConnection->CommitTrans();
......
m_pRecordset->MoveNext();
}
if(m_pRecordset)m_pRecordset->Close();
}

解决方案 »

  1.   

    错误好像并不在你说的哪里,我把你的代码复制到我的工程中,单步
    跟踪了一下,在事务的BeginTrans处并没有出错,你再看看你其他的代码
    是否会引起这个错误
      

  2.   

    说点其他的:
    if(m_pRecordset)m_pRecordset->Close();
    这一句有没有问题?
    如果前面记录集已经关闭了,那
    单单这一句就要导致异常的出现。
    应该这样写:
    if(m_pRecordset->State == adStateOpen)
    {}
      

  3.   

    说点其他的:
    if(m_pRecordset)m_pRecordset->Close();
    这一句有没有问题?
    如果前面记录集已经关闭了,那
    单单这一句就要导致异常的出现。
    应该这样写:
    if(m_pRecordset->State == adStateOpen)
    {
        m_pRecordset->Close();
    }
      

  4.   

    在开始事务之前,最好先检验一下这个连接是否支持事务。
       并非所有提供者都支持事务。需验证提供者定义的属性“Transaction DDL”是否出现在 Connection 对象的 Properties 集合中,如果在则表示提供者支持事务。如果提供者不支持事务,调用其中的某个方法将返回错误。
      

  5.   

    连接肯定支持事务,而且我把事务处理语句去掉,m_pConnection->Execute的执行都很正常。
    我程序的其它部分不会有问题的。
      

  6.   

    如果不介意 可以把代码发到 [email protected]我看一下!
      

  7.   

    1.同意瞎子 
    if(m_pRecordset!=NULL)
    {
    m_pRecordset->Close();
    }
    2.在开始事务之前,最好先检验一下这个连接是否支持事务,CanTransact()
    并非所有提供者都支持事务,"把事务处理语句去掉,m_pConnection->Execute的执行都很正常"并不能说明"连接肯定支持事务",这个论断不对.
      

  8.   

    如果可以,我给你看一下[email protected]
      

  9.   

    to yintongshun(踏雪有痕):
    给我个代码吧,谢谢。
    [email protected]
      

  10.   

    你把详细的代码贴出来啊,不一定是BeginTrans的错误