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

    Question Unanswered: Server reconnection logic

    Hi,

    I am a bit of a novice to SQL Server programming. So, forgive me if my question is too silly or easy.

    I have an client-server application where the server connects to an SQL Server and does simple DB operations. In a particular test case, after my SQL Server is shut down and restarted when I try to execute an SQL Statement, the SQLExecute function fails. The problem is that the connection handle used to allocate and prepare the statement is invalid. So, I need to reconnect to the server.

    Now my question is, how do I determine if the connection handle is valid or not ? That is, is there any API/function which when used can detect whether the connection handle is invalid or not.

    I have tried calls to SQLGetConnectAttr and SQLGetInfo passing the connection handle, but these API's still return the correct value even if the handle is invalid.

    Thanks in advance,

    Ganesh

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    By default if the SQL Services are restarted then you must invoke connection from client to execute the process.

    SQL will never disconnects on its own until that process is killed or services are restarted.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  3. #3
    Join Date
    Mar 2004
    Posts
    2
    Originally posted by Satya
    By default if the SQL Services are restarted then you must invoke connection from client to execute the process.

    SQL will never disconnects on its own until that process is killed or services are restarted.
    That is exactly my question... How do I determine (in my code) if my SQL Services have been restarted or not.

  4. #4
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    Why don't you use SQLConnect Function before executing process.
    For information review this http://msdn.microsoft.com/library/de...sqlconnect.asp link.

    HTH
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

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