locked
How to find the database conection is open or not in enterprise library 4.1? RRS feed

  • Question

  • User430178104 posted

    Hi,

      How to find the database conection is open or not in enterprise library 4.1?

    here i want if conection is open i need to close it

    so i writen the code loke below, but for every tiime its not going to loop

     if (command.Connection.State == ConnectionState.Open)

    {

    command.Connection.Close();

    }

    Tuesday, March 9, 2010 11:01 PM

All replies

  • User-1234160842 posted

    If you are using enterprise library data access application block , you don't need to open or close connection explicitly, just call the appropriate method on the database object, it will execute the method and close the connection itself. The exception is when you use reader , in that case you should use the using block.

    have a look at this article 

    managing connections

    http://msdn.microsoft.com/en-us/library/dd203181.aspx


    also see the key scenarios, you will see that they are not opening or closing the connection explicitly any where.


    http://msdn.microsoft.com/en-us/library/dd203113.aspx

    Wednesday, March 10, 2010 2:10 AM
  • User430178104 posted

    thank you 

    Wednesday, March 10, 2010 3:51 AM