SqlConnection Check if still online RRS feed

  • Question

  • Hi,

    I have an application in which I have an Sql connection which I open at the begining of my application and I always use the same conneciton to get DataReader and execute sql commands and this work fine but I am not sure its the proper way to use an SqlConnection. Now my real problem is that some of my users use laptop and when laptops go to sleep they loose there network connection and therefore my connection  to the database is lost. So before running any command I need to check if the connection is still available so just in case not I reconnect  to the database.

    1. Is there a way to check if the connection is still avialable?

    2. Is it a good practice to open a connection on startup of my application and use that connection?




    Saturday, January 8, 2011 2:37 PM