In the development of ADO applications, there are always a lot of inexplicable errors. Idispatch error 3121 is one of them. I have also checked the solution on the Internet and it is not easy to use. So let's share it with you, this error is returned when an SQL command times out. It does not mean that the Connection times out. In the Connection object, there is a ConnectionTimeOut parameter, which indicates that the Connection times out, for example, if you execute m_pConnection-> ConnectionTimeOut = 15m_pConnection-> Open (newVal, "", "", adConnectUnspecified) for more than 15 seconds, the database connection has not been established, and an error occurs. It does not mean the idle time of the connection, but refers to the timeout when the SQL statement is executed. It is controlled by the CommandTimeout attribute. The default value is 30 seconds. If the result is not obtained after the SQL statement is executed for more than 30 seconds, the error "IDispatch error 3121" is returned. Someone has set this parameter to 30000 on the Internet. In fact, this is not so troublesome. If you don't want it to time out, set it to 0 and it will never time out. Example: 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;
}
This article from the "jinghou Jiayin" blog, please be sure to keep this source http://thomas.blog.51cto.com/177910/30587