运行VS2008时,出现错误,指出Sqlcon.Open();出现错误,我不太懂。是初学者。

public partial class Edit : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { string StrID = Request["ID"]; string Com = "select * from tb_Vote where ID=✀"+StrID+"✀"; SqlConnection Sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConStr"]); ——> Sqlcon.Open(); SqlCommand SqlCom = new SqlCommand(Com, Sqlcon); SqlDataReader dr = SqlCom.ExecuteReader(); dr.Read(); if (!IsPostBack) { this.txtSubject.Text = dr["Title"].ToString(); this.txtContent.Text = dr["Content"].ToString().Replace("|", "尀n"); } dr.Close(); }
2026年09月22日 04:26
有2个网友回答
网友(1):

报告什么错误?

你确认下,ConfigurationManager.AppSettings["ConStr"]的值是多少,内容是否真的能访问(如服务器地址是否正确、帐户与密码是否匹配、数据库是否对应等)。

此外,是否你的网络禁止访问1433端口(SQL的默认服务端口),电信的ADSL网络是禁止对外提供1433端口服务的。

网友(2):

SqlCon应该定义在前面