C++ Ado 执行存储过程报 IDispatch error #3121 错误解决方案

下面是从网上搜出的方案:

 

//catch   _com_error   exception   for   more   information   here.i   guess   it   is    
  CAUSE  
  ADO   doesn't   fill   in   the   out   parameters   for   a   recordset   created   using   adUseServer   (server   side   cursor)

  until   the   returned   recordset   is   closed.    
  RESOLUTION  
  Use   one   of   the   following   methods   to   get   the   correct   output   values   from   the   stored   procedure.  
  Select   Client   side   server   adUseClient.   In   the   code   below   insert   the   following   line   just   before   the  

comm->Execute()   call.  
  conn->CursorLocation=adUseClient;    
  Close   the   returned   recordset   before   getting   the   value   of   the   output   parameter.   In   the   code   below  

insert   the   following   line   just   before   obtaining   the   parameter   values.  
  rs->Close();  
  for   more   details   ,see  
  PRB:   SQL   Server   Stored   Procedure's   Out   Parameters   Can   Return   Incorrect   Values    
  ID:   Q224591    

 


在开发ADO应用中,老是碰到很多莫名奇妙的错误,Idispatch error 3121就是其中一个,也查过网上的解决办法,不太好用,所以写出来大家共享一下

,这个错误是在执行一条SQL命令超时时报的错误,不是指链接超时,在Connection对象里有一个参数ConnectionTimeOut,它是指建数据库链接时的超

时,如执行
m_pConnection->ConnectionTimeOut = 15
m_pConnection->Open(newVal,"","",adConnectUnspecified)
如果超过15秒,还没建立数据库链接,就会出错了。
也不是指连接空闲的时间,而是指执行SQL语句时的超时,它是通过CommandTimeout 属性来控制的,缺省是30秒。就是如果执行SQL语句超过30秒还没有

取到结果就会出IDispatch error 3121错误。在网上见到有人把它这个参数设置成30000,其实不用那么麻烦,如果你不想它超时设为0就可以了,它永

不超时。例子如下
 try
 {
  // Build DB Connection
  HRESULT hr = m_pConnection.CreateInstance(__uuidof(Connection)); 
  if(FAILED(hr)) return S_FALSE;
  hr = m_pConnection->Open(newVal,"","",adConnectUnspecified);
  if(SUCCEEDED(hr))
  {
   m_pConnection->CommandTimeout = 0;
   m_pRs.CreateInstance(__uuidof(Recordset));
   return S_OK;
  }
  else return S_FALSE; 
 }
 catch(_com_error e) // Capture exceptions
 {
  GetErrorMsg(e.ErrorMessage());
  return S_FALSE;
 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值