[英]Login failed for user 'username'
我有一個從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");
}
}
}
您看到的Ticket類只是一個類,其中包含從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;
}
}
我將在本地主機服務器上對此進行測試,以查看是服務器還是我的代碼引起了錯誤,但是我仍然願意就此特定問題提出建議/支持。
提前致謝!
這看起來像是與SQL登錄相關的錯誤(與Windows身份驗證無關)。
打開SSMS,嘗試使用以下命令打開查詢窗口:
它會失敗嗎?
如果是,則有一些選項(以其他方式連接之后):
如果不是,則您的應用存儲了錯誤的憑據
編輯,評論后。
在查詢窗口中,右鍵單擊,連接,更改連接...使用上面的第一個項目符號指示列表重新連接到相同的SQL Server實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.