Search code examples
asp.netado.netconnection-pooling

how to close connection/datareader when using SqlDataSource or ObjectDataSource


during beta testing we discovered connection pooling error messages . Therefore I have been going through the code and closing down the SqlDataReader objects wherever they have been left unclosed. What I need to know is how to close a datareader (or if there is a need at all to close) that is specified in the SelectStatement attribute of the SqlDataSource or ObjectDataSource tags. Could there be connection leak if they are not handled?

Thanks in advance !


Solution

  • I tend to use the "using" keyword, especially when dealing with opening and closing connections to a database. "using" is a shortcut to the Dispose pattern - here is a link to the MSDN writeup, and here is a link to a useful blog entry with an overview.