Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 195489 - Last Review: July 6, 2006 - Revision: 2.3
CommandTimeout does not inherit from Connection timeout
This article was previously published under Q195489
If a Connection's CommandTimeout property is set to some value and a
Command object is associated to that Connection, the Command object does
not pickup the Connection's CommandTimeout setting. Instead, the Command
object's CommandTimeout is set to its default setting or whatever it was
set to prior to being associated with the Connection.
ActiveX Data Objects (ADO) does not practice inheritance. Due to the stand
alone capability of its objects, a Command object can be associated with
more than one Connection object. The one exception is the CursorLocation
property.
Specifically set the Command object's CommandTimeout.
This behavior is by design.
Steps to reproduce the behavior
- Start a Visual Basic Project.
- Set a Project Reference to the Microsoft ActiveX Data Objects Library.
- Paste the following code in the Form_Load() event of the default form.
You need to modify the connection string so that it references a valid
datasouce.
Dim cnn As New ADODB.Connection
Dim cnstring As String
cnstring = "Provider = SQLOLEDB;" & _
"DATA SOURCE =<server name>;" & _
"USER ID = <user id>;" & _
"PASSWORD =<password>;" & _
"INITIAL CATALOG = <database>;"
cnn.CommandTimeout = 0
cnn.Open cnstring
Dim cmd As New ADODB.Command
cmd.ActiveConnection = cnn
Debug.Print "Timeout on Connection: " & cnn.CommandTimeout
Debug.Print "Timeout on Command: " & cmd.CommandTimeout
- Run the form. You should see that the timeout for the Connection object is
set to zero (0) as expected, while the timeout for the Command object is 30 seconds (which is the
default).
APPLIES TO
- Microsoft Data Access Components 1.5
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1 Service Pack 2
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
- Microsoft Data Access Components 2.8
| kbdatabase kbprb KB195489 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate