|
I use SqlDataReader to return a string in a page, and I use using to automatically close the SqlDataReader, but when there are multiple such SqlDataReaders in a page (such as 10), more than 10 will be generated in the database Threads, stuffed my database thread pool, can't figure it out, please help! Thank you
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;
} |
|