I find that I am having problems with the connection pool to the website, and I am in the process of tracking them. I know one thing I need to look for to make sure that any SQLDataReaders are closed, and I went, although I am sure that they are. One of the questions that arose in my head concerned the methods that return SQLDataReaders and how they are closed (or not).
So, here is how I have the settings and some example methods:
public static SqlDataReader ExecuteReader(SqlCommand cmd)
{
SqlConnection c = new SqlConnection(Properties.Settings.Default.DatabaseConn);
cmd.Connection = c;
c.Open();
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
then I have a method that uses 'ExecuteReader ()'
public static SqlDataReader GetData()
{
SqlCommand Query = new SqlCommand("select * from SomeTable");
return ExecuteReader(Query);
}
Now say that I have another method that calls "GetData". I obviously simplified things.
public static SqlDataReader GetMoreData()
{
return GetData;
}
So my question is when I call "GetMoreData" as follows
SqlDataReader dr = GetMoreData();
//do some stuff with 'dr'
dr.close();
Are all my SqlDataReaders and connections closed correctly?
Thank!