I have a form that selects a bunch of rows from a table in my MSSQL server, now, this form is used to update data, which it does correctly, after I update the data using the form however, it redirects back to a page with a datagrid of all the rows in that table, and allows me to select another row to update, if I select the row I just updated again, I'm greeted with "Login failed for user 'slehan_ticketadmin'."
Now I know the username/password are correct, because I used the form a minute ago in order to update the data. I can't view the SQL Error Logs because my host limits me, but here is my code behind for the update form.
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");
}
}
}
The Ticket class you see, is just a class that holds the data for the tickets that are updated/selected/deleted from the SQL Server, it's just an easy way for me to modify/hold data in a structured way. I want to bring your attention to the line:
Ticket ticketBeingUpdated = TicketDatabase.selectTicketFromDatabase(sqlErrorLabel, ticketID);
I have another class called TicketDatabase that has a bunch of methods that insert/select/update/delete tickets from the database. Here is the selectTicketFromDatabase() method stub.
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;
}
}
I'm going to test this on a localhost server to see if it's the server or my code causing the error, but I'm still open to suggestions/support to this particular issue.
Thanks in advance!