J
Julien Cheyssial
Hi all,
To summarize my problem, I'd like to know if it's better to open many short
SqlConnection for each database calls, or one longer SqlConnection used by
all database calls.
Let's say I have a function called "GetMyPageData()" in my Business Logic
Layer :
function GetMyPageDataInXml(XmlDocument output, int userId)
{
MyDAL.GetUserInfos(userId, output);
MyDAL.GetUserItems(userId, output);
}
This functions let me get some data in about a User and its items. My Data
Access Layer is based on the Microsoft Data Access Application Block (v2.0)
and GetUserInfos() and GetUserItems() both are implemented like this :
string spName = "GetUserInfos";
SqlParameter[] spParams =
{
SqlHelper.MakeInParam("@UserId", SqlDbType.Int, 4, userId)
};
SqlDataReader reader =
SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings["ConnectionString"
], CommandType.StoredProcedure, spName, spParams);
....
SqlHelper.ExecuteReader() manages the SqlConnection itself. But, since I
make two calls to ExecuteReader (one for GetUserInfos, and another one for
GetUserItems), I guess two connections are being opened and closed. Should I
manage the SqlConnection myself in order to open only one connection for
such a request ?
Thanks
Julien C.
To summarize my problem, I'd like to know if it's better to open many short
SqlConnection for each database calls, or one longer SqlConnection used by
all database calls.
Let's say I have a function called "GetMyPageData()" in my Business Logic
Layer :
function GetMyPageDataInXml(XmlDocument output, int userId)
{
MyDAL.GetUserInfos(userId, output);
MyDAL.GetUserItems(userId, output);
}
This functions let me get some data in about a User and its items. My Data
Access Layer is based on the Microsoft Data Access Application Block (v2.0)
and GetUserInfos() and GetUserItems() both are implemented like this :
string spName = "GetUserInfos";
SqlParameter[] spParams =
{
SqlHelper.MakeInParam("@UserId", SqlDbType.Int, 4, userId)
};
SqlDataReader reader =
SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings["ConnectionString"
], CommandType.StoredProcedure, spName, spParams);
....
SqlHelper.ExecuteReader() manages the SqlConnection itself. But, since I
make two calls to ExecuteReader (one for GetUserInfos, and another one for
GetUserItems), I guess two connections are being opened and closed. Should I
manage the SqlConnection myself in order to open only one connection for
such a request ?
Thanks
Julien C.