Select conn. State and conn. errors. Count

Source: Internet
Author: User

Sit down at work in the morning, start up, open the familiar Work website interface, and suddenly find the website prompts that the database link failed, however, the system's error interception is ineffective (the reason for the database connection is that the database server is not open, which is not the focus of this Article ).
Check the code to determine whether the connection is successful.
If conn. errors. Count <> 0 and conn. errors. Count <> 2 then
Display link failure prompt
End if
Think of it, it was originally using Conn. errors. count <> 0 to determine whether the connection is successful, but always misjudgment, trace the cause, it is found that when the database connection sometimes produces Conn. errors. count is equal to 2, but the link is successful, so a Conn is added. errors. count <> 2, but this conn. errors. count = 2 contains all the reasons for the connection failure, so the scene described above occurs.

After thinking for a long time, I didn't come up with a solution. When I went to the bathroom and fainted, I thought that conn had an attribute to check the connection status (why did I think of it when I went to the bathroom ?), I checked the CHM manual of ADO and found the state attribute. Below are some values of this attribute.
Adstateclosed indicates that the object is disabled by default.
Adstateopen indicates that the object is open.
Adstateconnecting indicates that the recordset object is being connected.
Adstateexecuting indicates that the recordset object is executing the command.
Adstatefetching indicates that the row of the recordset object is being read.

Check adovbs. ini. The actual values of these statuses are:
Const adstateclosed = & h00000000
Const adstateopen = & h00000001
Const adstateconnecting = & h00000002
Const adstateexecuting = & h00000004
Const adstatefetching = & h00000008

State is a combination value. For example, when the State is adstateexecuting recordset object is executing a command, the true value should be a combination of adstateopen and adstateexecuting. You can try the specific combination format. My focus is on the first parameter adstateclosed. It is obvious that the decimal value of adstateclosed is 0.
That is to say, when conn. State <> 0, the link is successful. Then, the sentence can be changed
If conn. State = 0 then
Display link failure prompt
End if
Test the success status of all errors and intercept operations are normal. Yeah ~ (This is infected by mm. I like to say yes. I am used to it if I want to vomit. -_-| B)

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.