CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    CRecordSet Timeout

    I connect to a remote database with CRecordSet derived class and ODBC. (MyODBC)

    The timeout of the remote DB is 5 minutes and I can not change it.

    Supposing the timeout time has passed.

    - Question 1:
    How can I detect the server has disconnected me? I tried CRecordSet::IsOpen() and CDabase::IsOpen() but are still given me TRUE.

    - Question 2:
    The problem is closing the CRecordSet and opening it again gives me a timeout error message. I have to close the application and run it again. What should I do in order to reconnect again with the DB without closing the Application?

    Thank you.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: CRecordSet Timeout

    I don't know if they'd help here, but have you tried the SetLoginTimeout and SetQueryTimeout methods of CDatabase?

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: CRecordSet Timeout

    Question 1:
    you could try ::SQLGetInfo () with the SQL_ACTIVE_CONNECTIONS flag.

    Another way is try to open a Recordset and surround it with a try/catch. If an error occurs you know the connection is gone

    Question 2:
    That's weird behaviour. You should be able to open and close a recordset as much as you like. I think you should try to find why you get a timeout.
    Last edited by Skizmo; December 11th, 2007 at 09:31 AM.

  4. #4
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Re: CRecordSet Timeout

    Quote Originally Posted by GCDEF
    I don't know if they'd help here, but have you tried the SetLoginTimeout and SetQueryTimeout methods of CDatabase?
    Thanky you.

    I think is a connection timeout matter since I already was connected and there is no query involved.

  5. #5
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Re: CRecordSet Timeout

    Quote Originally Posted by Skizmo
    Question 1:
    you could try ::SQLGetInfo () with the SQL_ACTIVE_CONNECTIONS flag.

    Another way is try to open a Recordset and surround it with a try/catch. If an error occurs you know the connection is gone
    I will try that way.

    Quote Originally Posted by Skizmo
    Question 2:
    That's weird behaviour. You should be able to open and close a recordset as much as you like. I think you should try to find why you get a timeout.
    I am sure the timeout happens because I have the recordset open without doing anything more time than the connection timeout of the server.

    I wonder why after closing the recordset when trying to open it again fails.
    I don't know how to restore the conection when this happens.

    The error message I receive is "MySQL server has gone away". I've read the help in mysql site about this issue but I don't find nothing helpful in order to restore the connection.

  6. #6
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Re: CRecordSet Timeout

    The only way I have found to solve the problem is to dynamically create and destroy the CRecordSet object. Then If I found it is timeout I destroy and create it again before calling Open().

    This solves the problem but is only a way to surround the problem.

    I still don't know where is and/or what is that hidden link between the recordset object and the server that allows the server to remember the recordset was timeout even though the recorset is closed.

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

Featured