简体   繁体   English

简单更新查询导致 System.ComponentModel.Win32Exception: The wait operation timed out error in C# 和 SQL 服务器

[英]Simple update query caused System.ComponentModel.Win32Exception: The wait operation timed out error in C# and SQL Server

I'm trying to create a Forgot password page, that verify the user's username, email, security question and answer, before sending them to the new password page.我正在尝试创建一个忘记密码页面,用于验证用户的用户名 email、安全问题和答案,然后再将其发送到新密码页面。 The code below is the onClick that redirect user to the new password page.下面的代码是将用户重定向到新密码页面的 onClick。

protected void SubmitButton_Click(object sender, EventArgs e)
{
        string email = Email.Text;
        string user = UserName.Text;
        string question = Question.Text;
        string answer = Answer.Text;

        string strCon = ConfigurationManager.ConnectionStrings["WebConfigConString"].ConnectionString;

        SqlConnection con = new SqlConnection(strCon);
        con.Open();

        string strCheck = "SELECT * FROM ACCOUNT WHERE ID = @id AND EMAIL = @email AND SECURITYQUESTION = @question AND SECURITYANSWER = @answer";
        SqlCommand cmdCheck = new SqlCommand(strCheck, con);

        cmdCheck.Parameters.AddWithValue("@id", user);
        cmdCheck.Parameters.AddWithValue("@question", question);
        cmdCheck.Parameters.AddWithValue("@email", email);
        cmdCheck.Parameters.AddWithValue("@answer", answer);

        SqlDataReader dtrCheck = cmdCheck.ExecuteReader();

        if (dtrCheck.HasRows)
        {
            Response.Redirect("newPassword.aspx?id=" + user);
        } 
        else
        {
            ErrorMsg.Text = "Invalid username or email / question and answer does not match!";
        }
}

And this code below is the form segment of the aspx page for newPassword.下面这段代码是newPassword的aspx页面的表单段。

<form runat="server">
     <div class="form-group">
         <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">
         Password:</asp:Label>

         <asp:TextBox class="form-control form-control-user" ID="Password" runat="server" TextMode="Password"></asp:TextBox>
         <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
              ErrorMessage="Password is required." ForeColor="Red">*</asp:RequiredFieldValidator>
     </div>
     <div class="form-group">
         <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">
                    Confirm Password:</asp:Label>
         <asp:TextBox class="form-control form-control-user" ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
         <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
              ErrorMessage="Confirm Password is required." ForeColor="Red">*</asp:RequiredFieldValidator>
         <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                            ControlToValidate="ConfirmPassword" ErrorMessage="The Password and Confirmation Password must match." ForeColor="Red">*</asp:CompareValidator>
     </div>

     <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
     <asp:Button ID="SubmitButton" runat="server" Text="Confirm" class="btn btn-primary btn-user btn-block" OnClick="SubmitButton_Click"/>
 </form>

And this is the codebehind onclick function for newPassword:这是新密码的 onclick onclick后面的代码:

protected void SubmitButton_Click(object sender, EventArgs e)
{
        string id = Request.QueryString["id"];
        string password = Password.Text;

        string strCon = ConfigurationManager.ConnectionStrings["WebConfigConString"].ConnectionString;

        using (SqlConnection con = new SqlConnection(strCon))
        {
            con.Open();

            string strChange = "UPDATE ACCOUNT SET PASSWORD = @password WHERE ID = @id";

            SqlCommand cmdChange = new SqlCommand(strChange, con);

            cmdChange.Parameters.AddWithValue("@id", id);
            cmdChange.Parameters.AddWithValue("@password", password);

            cmdChange.ExecuteNonQuery();

            con.Close();

            Response.Redirect("login.aspx?msg=Password updated successfully!");
        }
}

However, whenever I click submit after filling out the new password, it freeze for a long time then display this error:但是,每当我在填写新密码后单击提交时,它会冻结很长时间然后显示此错误:

System.ComponentModel.Win32Exception: The wait operation timed out error System.ComponentModel.Win32Exception:等待操作超时错误

Apparently, I forgot to close the connection before redirecting the user to the newPassword.aspx, simply add a con.Close() before redirecting worked for me.显然,我忘记在将用户重定向到 newPassword.aspx 之前关闭连接,只需在重定向对我有用之前添加一个 con.Close() 即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.ComponentModel.Win32Exception:等待操作从Azure VPN超时 - System.ComponentModel.Win32Exception: The wait operation timed out from Azure VPN System.ComponentModel.Win32Exception c# - System.ComponentModel.Win32Exception c# Selenium C#System.ComponentModel.Win32Exception&#39;发生在System.dll错误中 - Selenium C# System.ComponentModel.Win32Exception' occurred in System.dll Error System.ComponentModel.Win32Exception:创建窗口处理程序C#时出错 - System.ComponentModel.Win32Exception: Error while creating a window handler C# C# - 打印 PDF 错误(System.ComponentModel.Win32Exception:...) - C# - Print a PDF Error (System.ComponentModel.Win32Exception:...) System.ComponentModel.Win32Exception:操作成功完成 - System.ComponentModel.Win32Exception: The operation completed successfully System.ComponentModel.Win32Exception:操作成功完成 - System.ComponentModel.Win32Exception: The Operation Complected successfully 获取异常System.ComponentModel.Win32Exception:系统找不到Sikuli C#中指定的文件 - Getting an Exception System.ComponentModel.Win32Exception : The system cannot find the file specified in Sikuli C# System.ComponentModel.Win32Exception:访问被拒绝...错误 - System.ComponentModel.Win32Exception: Access is denied… Error 在窗口7中从c#打开叙述者时,system.componentmodel.win32exception = {“系统找不到指定的文件”}错误 - system.componentmodel.win32exception = {“the system cannot find the file specified”} error when opening narrator from c# in window 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM