Setting the Command Timeout
By default, the command timeout value for ADO.NET is 30 seconds. At times you may want to increase this value to allow for queries that take a long time. The MM .NET data access classes have a CommandTimeout property that can be used to change the timeout period.
For example, if you want to temporarily change the timeout period when issuing a particular command, you can do it as follows:
public EmployeeEntity GetEmployeesBySSN(string ssn) { // Set the CommandTimeout property mmDataAccessBase dao = this.GetDataAccessObject(); // Get the original value int commandTimeout = dao.CommandTimeout; // Set a new value dao.CommandTimeout = 60; // Execute the command EmployeeEntity employeeEntity = this.GetEntity("GetEmployeeBySSN", this.CreateParameter("@SSN", ssn)); // Reset the CommandTimeout property dao.CommandTimeout = commandTimeout; return employeeEntity; }
And in VB .NET:
Public Function GetEmployeesBySSN(ByVal ssn As String) As EmployeeEntity '' Set the CommandTimeout property Dim dao As mmDataAccessBase = Me.GetDataAccessObject() '' Save original value Dim commandTimeout As Int = dao.CommandTimeout '' Set a new value dao.CommandTimeout = 60 '' Execute the command Dim employeeEntity As EmployeeEntity = Me.GetEntity("GetEmployeeBySSN", Me.CreateParameter("@SSN", ssn)) '' Reset the CommandTimeout property dao.CommandTimeout = commandTimeout Return employeeEntity End Function
If you want to permanently change the CommandTimeout property for all data access classes you can override the corresponding data access factory method in your application-level Factory class.
For example, in C#:
public override mmDataAccessSql CreateDataAccessSql() { mmDataAccessSql dao = base.CreateDataAccessSql(); dao.CommandTimeout = 60; return dao; }
And in VB .NET:
Public Overrides Function CreateDataAccessSql() As mmDataAccessSql Dim dao As mmDataAccessSql = MyBase.CreateDataAccessSql() dao.CommandTimeout = 60 Return dao End Function
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/29/18
Comment or report problem with topic
