Results 1 to 7 of 7

Thread: Frequent Timeout Expired Problem

  1. #1

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    Frequent Timeout Expired Problem

    Hi. Im using the code below but everytime somebody runs a huge script on query analyzer or the server is having a processing a huge load, my program experiences timeout. Im using functions to ease coding. Is there any problem with my code? How can I improve it so that I wouldn't receive any timeouts or timing out is normal? Thank you very much....

    Code:
    Public Sub EstablishConnection(ByRef pCon As Connection)
       Set pCon = New Connection
       pCon.ConnectionTimeout = 0
       pCon.CommandTimeout = 0
       pCon.ConnectionString = gConnectionString
       'gConnectionString = "Provider='SQLOLEDB.1';Persist Security Info='False';Data Source='" & txtServerName + "'; Initial Catalog='" & txtDbaseName.Text & "'; User ID='" & txtUserName & "'; password='" & txtPassword & "
    End Sub
    
    Public Sub EstablishRecordsource(ByRef pRst As Recordset, ByVal pSource As String, ByRef pActiveCon As Connection, ByVal pCursorType As CursorTypeEnum, ByVal pOptions As Long)
       Set pRst = New Recordset
       pRst.Open pSource, pActiveCon.ConnectionString, pCursorType, adLockOptimistic, pOptions
    End Sub
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Frequent Timeout Expired Problem

    You should never get a Timeout error with a CommandTimeout = 0.

    The problem is that the EstablishRecordsource procedure is not using an existing connection but is opening a new connection. Thus the default CommandTimeout of 30 seconds is being used.

    Not sure why you are using the ConnectionString property of the pActiveCon variable when it seems you could just use

    pRst.Open pSource, pActiveCon, pCursorType, adLockOptimistic, pOptions

  3. #3

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    Re: Frequent Timeout Expired Problem

    The problem is that the EstablishRecordsource procedure is not using an existing connection but is opening a new connection. Thus the default CommandTimeout of 30 seconds is being used.
    So meaning I have to set the CommandTimeout property again to 0? Does this mean that if you pass a connection object ByRef its doesn't capture all the other attributes of the original connection object?

    Not sure why you are using the ConnectionString property of the pActiveCon variable when it seems you could just use
    I too am not sure why because everytime I omit the ConnectionString property of pActiveCon I get an error message saying:

    "The connection cannot be used to perform this operation. It is either closed or invalid in this context"

    Perhaps it has something to do with the pass by ref that Im trying to do? Should I just combine the two procedures?
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Frequent Timeout Expired Problem

    I too am not sure why because everytime I omit the ConnectionString property of pActiveCon I get an error message saying:

    "The connection cannot be used to perform this operation. It is either closed or invalid in this context"
    Well, you do need to open the Connection before you can use it to open a Recordset. I assumed the calling process was opening it.

  5. #5

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    Re: Frequent Timeout Expired Problem

    Perhaps the passing by ref doesn't work?

    I still don't know why I'm timing out, should I not use the subs?
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Frequent Timeout Expired Problem

    Try this

    VB Code:
    1. Public Sub EstablishRecordsource(ByRef pRst As Recordset, ByVal pSource As String, ByRef pActiveCon As Connection, ByVal pCursorType As CursorTypeEnum, ByVal pOptions As Long)
    2.    Set pRst = New Recordset
    3.    If pActiveCon.State = adStateClosed Then
    4.          pActiveCon.Open
    5.    End If
    6.    pRst.Open pSource, pActiveCon, pCursorType, adLockOptimistic, pOptions
    7. End Sub

  7. #7

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    Re: Frequent Timeout Expired Problem

    I replaced my code with your suggestion. It did solve the my problem of still using the ConnectionString property of pActiveCon.

    I haven't tested it with the timeout problem yet. Should I add the pActiveCon.ConnectionTimeout = 0?


    Thanks
    C++ Programming is overwhelming.

    Dont let it overwhelm you or you'll fall into the oblivion of its perfection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width