|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Closing of data reader..............MyReader.ExecuteReader(CommandBehavior.CloseConnection)
I am using the above statement for the reader object. Closing of connection object is taken care in the above statement. Do I have to close the 'Reader' exclusively? ..Net 1.1. Thank you, Smith "Lowry Smith" <LowrySmit***@hotmail.com> wrote Yes, if the SqlDataReader is created with CommandBehavior set to CloseConnection, closing the SqlDataReader closes the connection automatically.> MyReader.ExecuteReader(CommandBehavior.CloseConnection) > I am using the above statement for the reader object. Closing of connection > object is taken care in the above statement. > > Do I have to close the 'Reader' exclusively? > http://msdn2.microsoft.com/en-us/library/y6wy5a0f.aspx "Carl Prothman" <c***@prothman.online.org> wrote Note there is one exception to this rule when using CommandBehavior.CloseConnection. When you bind the SqlDataReader to an ASP.NET control (e.g. DataGrid), the connection is closed after the ExecuteReader method has returned all of the records. > "Lowry Smith" <LowrySmit***@hotmail.com> wrote >> MyReader.ExecuteReader(CommandBehavior.CloseConnection) >> I am using the above statement for the reader object. Closing of connection >> object is taken care in the above statement. >> Do I have to close the 'Reader' exclusively? > > Yes, if the SqlDataReader is created with CommandBehavior set to CloseConnection, closing the SqlDataReader closes the connection automatically. > http://msdn2.microsoft.com/en-us/library/y6wy5a0f.aspx >
Show quote
"Carl Prothman" <c***@prothman.online.org> wrote in message Isn't that always the case? I mean you can close a SqlDataReader only when news:uCAr5MbmGHA.4512@TK2MSFTNGP04.phx.gbl... > "Carl Prothman" <c***@prothman.online.org> wrote >> "Lowry Smith" <LowrySmit***@hotmail.com> wrote >>> MyReader.ExecuteReader(CommandBehavior.CloseConnection) >>> I am using the above statement for the reader object. Closing of >>> connection >>> object is taken care in the above statement. >>> Do I have to close the 'Reader' exclusively? >> >> Yes, if the SqlDataReader is created with CommandBehavior set to >> CloseConnection, closing the SqlDataReader closes the connection >> automatically. >> http://msdn2.microsoft.com/en-us/library/y6wy5a0f.aspx >> > > Note there is one exception to this rule when using > CommandBehavior.CloseConnection. When you bind the SqlDataReader to an > ASP.NET control (e.g. DataGrid), the connection is closed after the > ExecuteReader method has returned all of the records. it has fetched all records. If you close it before, it will still fetch all records and then close. -- Miha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ I think I was not clear about my question.
The question is, whether I have to write the below statement or not? MyReader.Close() Since I am using 'CommandBehavior.CloseConnection', once the data are fetched completely, the connection is closed. And alll the associated resources are released (in this case Data Reader)??. Now, Is it necessary to call MyReader.Close? Thank you for your answers, Smith Show quote "Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:O%23x$$ybmGHA.2452@TK2MSFTNGP04.phx.gbl... > > "Carl Prothman" <c***@prothman.online.org> wrote in message > news:uCAr5MbmGHA.4512@TK2MSFTNGP04.phx.gbl... > > "Carl Prothman" <c***@prothman.online.org> wrote > >> "Lowry Smith" <LowrySmit***@hotmail.com> wrote > >>> MyReader.ExecuteReader(CommandBehavior.CloseConnection) > >>> I am using the above statement for the reader object. Closing of > >>> connection > >>> object is taken care in the above statement. > >>> Do I have to close the 'Reader' exclusively? > >> > >> Yes, if the SqlDataReader is created with CommandBehavior set to > >> CloseConnection, closing the SqlDataReader closes the connection > >> automatically. > >> http://msdn2.microsoft.com/en-us/library/y6wy5a0f.aspx > >> > > > > Note there is one exception to this rule when using > > CommandBehavior.CloseConnection. When you bind the SqlDataReader to an > > ASP.NET control (e.g. DataGrid), the connection is closed after the > > ExecuteReader method has returned all of the records. > > Isn't that always the case? I mean you can close a SqlDataReader only when > it has fetched all records. If you close it before, it will still fetch all > records and then close. > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > Yes, why not?
CloseConnection means to close the connection when the reader is closed - and unless you dispose or/and close datareader it isn't closed at that time. -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Lowry Smith" <LowrySmit***@hotmail.com> wrote in message news:%233PTOghmGHA.4512@TK2MSFTNGP04.phx.gbl... >I think I was not clear about my question. > The question is, whether I have to write the below statement or not? > MyReader.Close() > Since I am using 'CommandBehavior.CloseConnection', once the data are > fetched completely, the connection is closed. And alll the associated > resources are released (in this case Data Reader)??. > Now, Is it necessary to call MyReader.Close? > Thank you for your answers, > Smith > > > > > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message > news:O%23x$$ybmGHA.2452@TK2MSFTNGP04.phx.gbl... >> >> "Carl Prothman" <c***@prothman.online.org> wrote in message >> news:uCAr5MbmGHA.4512@TK2MSFTNGP04.phx.gbl... >> > "Carl Prothman" <c***@prothman.online.org> wrote >> >> "Lowry Smith" <LowrySmit***@hotmail.com> wrote >> >>> MyReader.ExecuteReader(CommandBehavior.CloseConnection) >> >>> I am using the above statement for the reader object. Closing of >> >>> connection >> >>> object is taken care in the above statement. >> >>> Do I have to close the 'Reader' exclusively? >> >> >> >> Yes, if the SqlDataReader is created with CommandBehavior set to >> >> CloseConnection, closing the SqlDataReader closes the connection >> >> automatically. >> >> http://msdn2.microsoft.com/en-us/library/y6wy5a0f.aspx >> >> >> > >> > Note there is one exception to this rule when using >> > CommandBehavior.CloseConnection. When you bind the SqlDataReader to an >> > ASP.NET control (e.g. DataGrid), the connection is closed after the >> > ExecuteReader method has returned all of the records. >> >> Isn't that always the case? I mean you can close a SqlDataReader only >> when >> it has fetched all records. If you close it before, it will still fetch > all >> records and then close. >> >> -- >> Miha Markic [MVP C#, INETA Country Leader for Slovenia] >> RightHand .NET consulting & development www.rthand.com >> Blog: http://cs.rthand.com/blogs/blog_with_righthand/ >> >> > > |
|||||||||||||||||||||||