ADO: IDispatch error 3121 troubleshooting

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.