SQL Server 2005에서 생성 된 데이터베이스에서 페이지 타일, 메타 설명을 가져 오는 데 아래 코드를 사용하고 있습니다. 내 사이트는 ASP.NET 2.0 및 C#. page_load
에ASP.NET 2.0 및 C#에서이 코드를 실행하는 중에 시간 초과 연결 오류가 발생했습니다
나는이 코드를 실행 오전 :
ad.Fill(dt)
에서
string query = "select MetaDescription, MetaKeywords, H1Text, Ptitle, H2Text FROM SeoText Where CatalogItemId ='" + this.CurrentEnsemble.ItemId + "'";
SqlConnection myconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBconnection"].ConnectionString);
SqlCommand SqlCmd = null;
SqlCmd = new SqlCommand(query, myconnection);
SqlDataAdapter ad = new SqlDataAdapter(SqlCmd);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows[0]["Ptitle"].ToString() == "")
{
this.Page.Title = this.CurrentEnsemble.Title;
}
else
{
this.Page.Title = this.CurrentEnsemble.Title + " " + dt.Rows[0]["Ptitle"].ToString();
}
HtmlMeta metaDesc = (HtmlMeta)Page.Header.FindControl("metaDesc");
if (dt.Rows[0]["MetaDescription"].ToString() == "")
{
metaDesc.Attributes.Add("Content", this.CurrentEnsemble.Title);
}
else
{
metaDesc.Attributes.Add("Content", dt.Rows[0]["MetaDescription"].ToString());
}
HtmlMeta metaKey = (HtmlMeta)Page.Header.FindControl("metaKey");
if (dt.Rows[0]["MetaKeywords"].ToString() == "")
{
metaKey.Attributes.Add("Content", "site general text");
}
else
{
metaKey.Attributes.Add("Content", dt.Rows[0]["MetaKeywords"].ToString());
}
HtmlGenericControl h1 = (HtmlGenericControl)Master.Master.Master.FindControl("h1top");
if (dt.Rows[0]["H1Text"].ToString() == "")
{
h1.InnerText = "site general text";
}
else
{
h1.InnerText = this.CurrentEnsemble.Title + " " + dt.Rows[0]["H1Text"].ToString();
}
HtmlGenericControl h2 = (HtmlGenericControl)Master.Master.Master.FindControl("h2bottom");
if (dt.Rows[0]["H2Text"].ToString() == "")
{
h2.InnerText = "site general text";
}
else
{
h2.InnerText = this.CurrentEnsemble.Title + " " + dt.Rows[0]["H2Text"].ToString();
}
오류가 발생을 내가 실수를 만드는 중이라서 어디 확실하지 않다.
감사는 감사 그것을
** 경고 ** 귀하의 코드는 SQL 주입 공격에 취약합니다. –
Daniel에게 답장을 보내 주셔서 감사합니다. select query where 절에 대해 이야기하고 계시다면, 사용자가 값을 입력하면 SQL Injection이 발생하기 쉽다는 것을 이해합니다.이 코드는 코드 뒤에 사용되고 아무도 아무 것도 입력하지 않습니다. , 그것의 모든 일은이 테이블 itemid에 대해 그것을 검사하는 데이터베이스로부터 제품 id와 같은 Ensemble Item Id를 움켜 잡는 것입니다. 내 주요 쟁점은 sqldatadapter.fill에서 시간 제한을 던지고 있다는 것입니다. 나는 sqldataadapter가 열린 연결과 닫힌 연결을 처리하도록 내버려두고있다. 그래서 연결을 닫지 않는 것 같지 않다. 이것은 매우 무작위로 발생한다. – niceoneishere