none
Error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. RRS feed

  • Question

  • I need to increase the time allowed for execution of a query. I know that I need to change the value of the CommandTimeout of the command object.

    However, I'm using a TableAdapter. I can't get to the SelectCommand property of the TableAdapter's Adapter.SelectCommand because this object doesn't seem to be created until you fire the GetData or Fill method.

    Does anyone know how to set the CommandTimeout property when that property is somewhere in a TableAdapter?




    Michael
    Saturday, February 21, 2009 2:49 PM

Answers

  • Hi Michael.
    Allright. I'm so sorry, I a bit hurry and didn't check my code.
    I found in my archive this:


    Namespace MyDatasetTableAdapters

        Partial Public Class MyTableAdapter

            Public Property CommandTimeout() As Integer

                Set(ByVal value As Integer)

                    For Each DBCommand As SqlClient.SqlCommand In Me.CommandCollection
                        DBCommand.CommandTimeout = 0
                    Next

                End Set

                Get

                End Get

            End Property

        End Class

    End Namespace

    Software Developer on .NET
    Monday, February 23, 2009 7:10 AM

All replies

  • Hi Dear Michael.

    1. Add new class to your solution and insert this code into the class.


    Namespace MyDatasetTableAdapters

        Partial Public Class MyTableAdapter

            Public Property CommandTimeout() As Integer

                Set(ByVal value As Integer)
                    Me.Adapter.SelectCommand.CommandTimeout = value
                End Set

                Get

                End Get

            End Property

        End Class

    End Namespace


    2. At where that you use your TableAdapter use this code:

    Dim adapter As New MyDatasetTableAdapters.MyTableAdapter
    adapter.CommandTimeout = 0


    you must set CommandTimeout value to 0, to specify unlimited query execution time.



    Software Developer on .NET
    Sunday, February 22, 2009 11:38 AM
  • Thanks so much for your reply. I followed your directions but found a similar error when I got to the following line:


    Me.Adapter.SelectCommand.CommandTimeout = value

    Object reference not set to an instance of an object.



    While in the debugger, when the error stops on that line, if you highlight the following:

        Me.Adapter.SelectCommand.CommandTimeout = value, the intellisense will tell you that there is still no object for the SelectCommand.

    Me.Adapter.SelectCommand = Nothing



    Maybe this command isn't "built" until the Fill or GetData.

    I would really appreciate any insight since you seem to really have a deep understanding of this.

    M
    Michael
    Sunday, February 22, 2009 5:03 PM
  • However, I believe that the following line:

    Me.CommandCollection(0).CommandTimeout = value
     
    in place of:

    Me.Adapter.SelectCommand.CommandTimeout = value

    corrects the problem.



    Michael
    Sunday, February 22, 2009 5:23 PM
  • Hi Michael.
    Allright. I'm so sorry, I a bit hurry and didn't check my code.
    I found in my archive this:


    Namespace MyDatasetTableAdapters

        Partial Public Class MyTableAdapter

            Public Property CommandTimeout() As Integer

                Set(ByVal value As Integer)

                    For Each DBCommand As SqlClient.SqlCommand In Me.CommandCollection
                        DBCommand.CommandTimeout = 0
                    Next

                End Set

                Get

                End Get

            End Property

        End Class

    End Namespace

    Software Developer on .NET
    Monday, February 23, 2009 7:10 AM
  • Great. Slight modification

    Namespace MyDatasetTableAdapters  
     
        Partial Public Class MyTableAdapter  
     
            Public Property CommandTimeout() As Integer  
     
                Set(ByVal value As Integer)  
     
                    For Each DBCommand As SqlClient.SqlCommand In Me.CommandCollection  
                        DBCommand.CommandTimeout = Value 
                    Next  
     
                End Set  
     
                Get  
     
                End Get  
     
            End Property  
     
        End Class  
     
    End Namespace 

    Michael
    Monday, February 23, 2009 10:59 AM