C# 用户“username”登录失败

C# 用户“username”登录失败,c#,asp.net,sql,sqlconnection,sqlexception,C#,Asp.net,Sql,Sqlconnection,Sqlexception,我有一个表单,它从我的MSSQL服务器中的一个表中选择一组行,现在,这个表单用于更新数据,它正确地执行了,在我使用表单更新数据之后,它重定向回一个包含该表中所有行的datagrid的页面,并允许我选择另一行进行更新,如果我再次选择刚更新的行,我会收到用户“slehan_ticketadmin”登录失败的提示 现在我知道用户名/密码是正确的,因为我一分钟前使用了表单来更新数据。我无法查看SQL错误日志,因为我的主机限制了我,但下面是我的更新表单代码 namespace YakStudios_Sup

我有一个表单,它从我的MSSQL服务器中的一个表中选择一组行,现在,这个表单用于更新数据,它正确地执行了,在我使用表单更新数据之后,它重定向回一个包含该表中所有行的datagrid的页面,并允许我选择另一行进行更新,如果我再次选择刚更新的行,我会收到用户“slehan_ticketadmin”登录失败的提示

现在我知道用户名/密码是正确的,因为我一分钟前使用了表单来更新数据。我无法查看SQL错误日志,因为我的主机限制了我,但下面是我的更新表单代码

namespace YakStudios_Support.ys_admin
{
    public partial class UpdateTicket : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int ticketID = Convert.ToInt32(Request.QueryString["ticketID"]); // Grabs the ?ticketid number from the URL
                Ticket ticketBeingUpdated = TicketDatabase.selectTicketFromDatabase(sqlErrorLabel, ticketID); // Creates a new Ticket object to be used by the form to populate the text boxes

                /* Form Field Population */
                // Email
                emailTxt.Text = ticketBeingUpdated.getEmail();

                // Date Submitted
                dateSubText.Text = ticketBeingUpdated.getDateSubmitted().ToString();

                // Ticket Class
                classDropDown.SelectedValue = ticketBeingUpdated.getTicketClass();

                // Ticket Status
                statusDrop.SelectedValue = ticketBeingUpdated.getStatus();

                // Subject
                subjectTxt.Text = ticketBeingUpdated.getSubject();

                // Text
                textTxt.Text = ticketBeingUpdated.getTicketContent();
            }
        }

        protected void editBtn_Click(object sender, EventArgs e)
        {
            emailTxt.Enabled = true;
            dateSubText.Enabled = true;
            classDropDown.Enabled = true;
            statusDrop.Enabled = true;
            subjectTxt.Enabled = true;
            textTxt.Enabled = true;
        }

        protected void submitBtn_Click(object sender, EventArgs e)
        {
            int ticketID = Convert.ToInt32(Request.QueryString["ticketID"]); // Grabs the ?ticketid number from the URL
            DateTime convertedDate = Convert.ToDateTime(dateSubText.Text);
            Ticket ticketUpdated = new Ticket(emailTxt.Text, convertedDate, subjectTxt.Text, textTxt.Text, statusDrop.SelectedValue, classDropDown.SelectedValue);
            TicketDatabase.updateTicketInDatabase(ticketUpdated, sqlErrorLabel, ticketID);
            Response.Redirect("ticketqueue.aspx");
        }
    }
}
您看到的Ticket类只是一个保存从SQL Server更新/选择/删除的Ticket数据的类,它只是一种以结构化方式修改/保存数据的简单方法。我想让你注意这句话:

Ticket ticketBeingUpdated = TicketDatabase.selectTicketFromDatabase(sqlErrorLabel, ticketID);
我有另一个名为TicketDatabase的类,它有一系列方法可以从数据库中插入/选择/更新/删除票据。下面是selectTicketFromDatabase方法存根

        public static Ticket selectTicketFromDatabase(Label sqlErrorLabel, int ticketID)
    {
        SqlCommand sqlCmd = new SqlCommand("SELECT * from yak_tickets");

        using (SqlConnection selSqlConn = new SqlConnection(sqlConn.ConnectionString))
        //using (sqlConn)
        {
            sqlCmd.Connection = selSqlConn;
            selSqlConn.Open(); // Open the SQL connection
            //sqlCmd.Connection = sqlConn;
            //sqlConn.Open(); // Open the SQL Connection

            SqlDataReader reader = sqlCmd.ExecuteReader();
            Ticket ticketReturning = null; // Initializes the ticketReturning but it's not allocated

            // Call during reading
            while (reader.Read())
            {
                /* Objects to hold values from reader */
                string emailString = reader["email"].ToString();
                DateTime dateSubbed = Convert.ToDateTime(reader["dateSubmitted"].ToString());
                string subjectString = reader["subject"].ToString();
                string textString = reader["ticketText"].ToString();
                string statusString = reader["statusid"].ToString();
                string classString = reader["ticketClass"].ToString();

                ticketReturning = new Ticket(emailString, dateSubbed, subjectString, textString, statusString, classString);
            }
            selSqlConn.Close();
            return ticketReturning;
        }
    }
我将在本地主机服务器上测试这一点,看看是服务器还是我的代码导致了错误,但我仍然愿意接受有关此特定问题的建议/支持


提前谢谢

这看起来像是与SQL登录相关的错误,与Windows身份验证无关

打开SSMS,尝试使用以下命令打开查询窗口:

使用用户名和密码 Login=slehan\u ticketadmin Password=您期望的密码。 它失败了吗

如果是,以下是以其他方式连接后的一些选项:

锁定检查SSMS中的slehan\u ticketadmin安全/用户节点 不存在,见上文 密码已更改/错误在安全/用户节点中更改密码 默认数据库不同,请在错误消息中告诉您 SQL Server仅设置为Windows身份验证 如果没有,则您的应用程序存储了错误的凭据

在评论之后编辑


在查询窗口中,右键单击、连接、更改连接。。。使用上面的第一个要点指令列表重新连接到同一个SQL Server实例。

这是Chrome还是任何浏览器中的一个奇怪问题?我注意到Chrome在某些情况下在凭据方面有一些奇怪的行为……我在Internet Explorer和Safari中试用过,结果都一样。我无法运行该脚本,它说没有名为Login的存储过程。啊,好的,是的,它允许我登录。奇怪的是,它做到了这一点,在我更新行之后,在我更新它之前,它工作得很好。我使用了一个本地数据库,它工作得很好,我可以选择,更新,再次选择,它工作得很好。这真奇怪。