下面是从网上搜出的方案:
//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;
}