Sit down in the morning, turn it on, open the familiar work website interface, suddenly discovered that the website prompts the database link failed, but the error interception of the system did not have the effect (the database link is not open, this is not the focus of this article). Check the code that judges whether the connection is successful is found to write if conn.errors.count <> 0 and conn.errors.count <> 2 THEN Show chain failed prompt End if, it turned out to use conn.errors.count <> 0 to determine if the connection is successful, but it always judges the mistake, tracking the reason, found that the result of conn.errors.count is equal to 2 when the database connection is connected, but the link is successful, so add a conn .rrors.count <> 2, but this conn.errors.count = 2 contains the reason why all connectors are unsuccessful, so that the scene mentioned above.
I didn't want to have a way for a long time. I have a toilet, fainted, actually thinking that CONN has an attribute of checking the connection status (why do you think of it when you go to the bathroom?), Come back to check ADO's CHM manual Find the State property, below is some value adstateclosed by default, indicating that the object is closed. The AdStateOpen indicator is open. AdstateConnecting Indicates that the Recordset object is being connected. AdstateExecuting Indicates that the Recordset object is executing the command. AdStateFetching Indicates the row of the Recordset object being read.
Checked adovbs.ini, the true value of these states is: Const adStateClosed = & H00000000Const adStateOpen = & H00000001Const adStateConnecting = & H00000002Const adStateExecuting = & H00000004Const adStateFetching = & H00000008
State is also a combined value. If the status is the AdStateExecuting Recordset object is executing the command, the true value should be a combination of AdStateOpen and AdstateExecuting. What kind of combination format, can try it. My current focus is the first parameter adstateclosed, very clearly the decimal value of AdStateClosed is 0. That is to say, when conn.state <> 0 is the success of the link. The judgment sentence can be changed to if Conn.State = 0 THEN Show Chain Failure Tips End IF Test All Error Successful status, intercepting everything is normal. Yea ~ (This is infected by MM, I like it, I want to vomit, I am used to it.-_- || b)