|
我在一个页面里用SqlDataReader返回一个字符串,而且我用using来自动关闭SqlDatareader,但是当我的一个页面里有多个这样的SqlDataReader的时候(如10个),就会在数据库里产生10多个线程,塞满我的数据库线程池,搞不明白,还请各位帮帮忙!谢谢
public string BindAdWords(int count,string location)
{
string sql = "SELECT Top " + count + " * FROM AdWords WHERE Location='" + location + "' AND IsCancel=0";
string path = System.Configuration.ConfigurationSettings.AppSettings["ReadAdWordsImage"];
string link = "";
string imagedefault = "";
Admin.DB db = new Admin.DB();
using (SqlDataReader dr = db.ExecuteReadSQL(sql))
{
if (dr.HasRows)
{
while(dr.Read())
{
link += "<tr>";
link += "<td align='center'>";
if (Convert.ToString(dr["AdImage"]) == "" || dr["AdImage"] == null)
{
link += imagedefault;
}
else
{
link += "<a href='" + dr["WebSite"].ToString() + "' target='_blank'><IMG alt='' src=" + path + dr["AdImage"].ToString() + "></a>";
}
}
link += "</td>";
link += "</tr>";
}
else
{
link += imagedefault;
}
return link;
}
DB:
public SqlDataReader ExecuteReadSQL(string sql)
{
sqlConn = new SqlConnection(connectionString);
cmd = new SqlCommand(sql,sqlConn);
SqlDataReader dr = null;
try
{
sqlConn.Open();
dr = cmd.ExecuteReader();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write("<font color='Red'>" + ex.Message.ToString() + "</font>");
}
return dr;
}
|
|