none
SqlConnection.StateChange is not firing when sever is closing RRS feed

  • Question

  • Hello. At the beginning server is working and i get first event from "StateChange". Then i close server but i don't receive event about it from "StateChange". I receive it only if i try to execute some sql command. Why is it? Is it possible to receive this event momentarily?
    Tuesday, June 11, 2013 4:45 PM

All replies

  • The server isn't closing the TCP socket object so you won't receive any notifications.  If the client impliments the TCP keepalive then an exception will occur when the keepalive fails.  the keepalive basically sents a TCP empty datagram from the client to server and the server if it running will send an ACK back.  what you are seing is typical of TCP connection when an application closes on one side of a connection and doesn't stop the low level socket class.


    jdweng

    Tuesday, June 11, 2013 4:57 PM
  • I can't implement keep alive because it's SqlConnection class and sql server. I don't understand what you mean under TCP socket object. When server is closing its socket is closing too. Other side can be notified about it through shutdown command.
    Tuesday, June 11, 2013 5:16 PM
  • Hi Booster,

    Does it work when close the connection on client?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 12, 2013 8:35 AM
    Moderator
  • Hi Mike. What do you mean when close the connection on client? I need notification about connection status on client. I don't need to close it on client.
    Wednesday, June 12, 2013 10:25 AM
  • Hi Booster,

    >>What do you mean when close the connection on client? 

    I mean in your application.

    >>I need notification about connection status on client.

    I want to know the event works fine.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 13, 2013 3:01 AM
    Moderator