gpt4 book ai didi

c# - 连接未关闭。连接的当前状态是打开

转载 作者:太空宇宙 更新时间:2023-11-03 18:59:07 25 4
gpt4 key购买 nike

我遇到了这个错误。我读过一些帖子说要使用 Using block ,但我有一个,但我仍然遇到错误。

我的代码隐藏是:

    protected void btnEdit_OnClick(object sender, EventArgs e)
{
MdlCommentsExtender.Enabled = true;
MdlCommentsExtender.Show();
Button button = (Button)sender;
string buttonId = button.ID;
string[] tokens = buttonId.Split('-');
ScriptManager.GetCurrent(this).SetFocus(this.txtCommentBox);

//**************************/
try
{

using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnCST"].ToString();
conn.Open();
SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = conn;
string CmdTxt = "Select CBL.ID, CBL.[Category], CBL.[Provision], CTL.MarkForReview, CTL.IssueType, CTL.Resolution, CTL.Feedback, CTL.TemplateID";
CmdTxt = CmdTxt + " from [tblCSTBenefitList] CBL";
CmdTxt = CmdTxt + " LEFT JOIN tblCSTTemplateList CTL";
CmdTxt = CmdTxt + " ON CBL.ID = CTL.BenefitID";
CmdTxt = CmdTxt + " where CBL.ID > '0'";
CmdTxt = CmdTxt + " ORDER BY CBL.[Category], CBL.[Provision] ASC";

cmd2.CommandText = CmdTxt;
SqlDataReader reader;
conn.Open();
reader = cmd2.ExecuteReader();
reader.Read();

lblBenCatX.Text = Convert.ToString(reader["Category"]);
lblBenProvX.Text = Convert.ToString(reader["Provision"]);
txtCommentBox.Text = Convert.ToString(reader["Feedback"]);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

/*******************************************/

//txtCommentBox.Text = "First: " + tokens[0] + " and then " + tokens[1] + "";
}

它发生在 conn.Open(); 行。有什么想法吗?

最佳答案

您尝试打开连接两次,您的方法中有 2 次 conn.Open(),但您较新,在尝试“重新打开”之前关闭连接。

您确定要打开连接两次吗?尝试删除第二个 conn.Open(),它应该确实有效。

关于c# - 连接未关闭。连接的当前状态是打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38854648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com