2009-12-28 172 views
0

我有一种形式,从我的MSSQL服务器中的表中选择一堆行,现在,这种形式用于更新数据,它正确地执行后,我更新数据使用然而,它会重定向到一个包含该表中所有行的数据网格的页面,并且允许我选择另一行进行更新,如果我选择了我刚刚更新过的那一行,则表示“用户登录失败'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"); 
     } 
    } 
} 

您所看到的票务类,仅仅是持有该更新/选择门票/从SQL Server删除数据的类,它只是让我修改在/保持数据的简单方法结构化方式。我想带你注意行:

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; 
     } 
    } 

我要测试该本地主机服务器上,看看它的服务器或我的代码导致错误,但我仍然愿意接受建议,以这种特殊的问题/支。

在此先感谢!

+0

随机奇科问题 - 这是在Chrome或任何浏览器?我注意到,在某些情况下,Chrome浏览器在凭证方面有一些奇怪的行为... – Will 2009-12-28 14:38:24

+0

我在Internet Explorer和Safari中尝试了它,两者的结果都一样。 – skylerl 2009-12-28 14:47:24

回答

2

这看起来像是与SQL登录相关的错误(与Windows身份验证不相关)。

打开SSMS,试图打开一个查询窗口:

  • “SQL Server身份验证”
  • 登录= “slehan_ticketadmin”
  • 密码=你所期望的密码是什么。

它失败了吗?

如果是的话,这里有一些选项(连接另一种方法后):

  • 锁定(检查SSMS slehan_ticketadmin安全/ Users节点)
  • 不存在(见上文)
  • 密码已更改/错误(在Security/Users节点中更改它)
  • 默认数据库不同(应在错误消息中告诉您)
  • SQL Se rver设置为Windows身份验证只

如果没有,你的应用程序有错误的凭证存储

编辑,注释之后。

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

+0

我无法运行该脚本,它表示没有名为Login的存储过程。 – skylerl 2009-12-28 14:56:53

+0

@Yakkattak:我的回答中没有脚本...请参阅编辑 – gbn 2009-12-28 15:10:39

+0

啊好的,是的,它允许我登录。奇怪的是,它是这样做的,在更新行之后,在我更新它之前,它工作正常。 – skylerl 2009-12-28 15:16:34