Monday, November 15, 2010

ExecuteReader with CommanBehavior ( automatically close connection after reading data)

Here in this post I am going to explain about the CommandBehavior which plays important role when your are getting data with the DataReader object from database.

Datareader object has method ExecuteReader, which has overload version that takes CommandBehavior enumeration as parameter.

- CommandBehavior.CloseConnection
   When you pass above values as argument to ExecuteReader
     1. there is no need to close connection explicitly connection get close when you close your reader.

     //No need to close connection you just have to write

     2. It usefull when you pass reader to another method for processing data.

- CommandBehavior.SinglerRow
   passing this as parameter , increase performance when you are executing query and retriving single row for exmaple by id field of table.

- CommandBehavior.SequentialAccess
   usefull when reading binary field data, which reduces the memory overhead for large binary fields.

1 comment:

  1. thank you very much, CommandBehavior.CloseConnection helped me on core.