Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    12

    Unanswered: How to get CDatabase to reconnect after SQL Server restart

    I have an old application to maintain that uses CDatabase to connect to SQL Server. If SQL Server is stopped and restarted, such as in a cluster failover (i.e. move group), then the CDatabase connection needs to reconnect. It seems that it's not capable of doing this on it's own so I need to check the state some how. Various methods, such as IsOpen, seem to be useless as far as determining if I have a "good" connection.

    Any thoughts?
    Nick

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    you may have to try sending a query to the server.

    you could add a method in your class called TryConnection that executes this:
    Code:
     select 1
    if it fails you know you don't have a good connection.
    Last edited by jezemine; 01-26-07 at 18:50.

  3. #3
    Join Date
    Mar 2004
    Posts
    12
    That's pretty much what I was thinking too. I was hoping to not have to go over the wire just to verify the link. In OLEDB/ADO I've been able to use DBPROPVAL_CS_COMMUNICATIONFAILURE pretty reliably and was hoping someone might come back with something similar. Even a straight ODBC call passing the member connection handle.

    Unfortunately the app isn't written in such a way that it's easy to trap and close up the connection and on a failure. CRecordsets are created on the stack all over the place with no encapsulation of the functionality. Some don't even have try...catch and just let the CATCH ALL handle it. Over the years people have kept adding functionality and used the same bad practices.
    Nick

  4. #4
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    good luck with that. sounds like a mess.


Posting Permissions

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