automatically all sessions are removed ....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajesh0303
    New Member
    • Jul 2008
    • 7

    automatically all sessions are removed ....

    Hi.

    Problem is that all sessions are removed when I am using this code...
    By this code I am deleting files in a particular folder and then that folder..

    Need help......

    code is:

    Code:
     try
            {
                string str;
    
                string username = (string)Session["username"];
                MySql.Data.MySqlClient.MySqlConnection oConn = new MySql.Data.MySqlClient.MySqlConnection(WebConfigurationManager.ConnectionStrings["filesystem"].ConnectionString);
    
                oConn.Open();
    
                MySql.Data.MySqlClient.MySqlCommand command =
                            new MySql.Data.MySqlClient.MySqlCommand("select * from usefiles where USERNAME=?user;", oConn);
    
                command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?user", MySql.Data.MySqlClient.MySqlDbType.VarChar, 500));
                command.Parameters[0].Value = (string)DropDownList1.SelectedValue;
                MySqlDataReader dr = command.ExecuteReader();
    
                while (dr.Read())
                {
                    string serialnumber = (string)dr["FILENAME"];
    
                    System.IO.File.Delete(Server.MapPath(".") + "\\USERFOLDERS\\" + DropDownList1.SelectedValue + "\\" + serialnumber);
    
                }
                oConn.Close();
    
    
    
                //if (str.Equals("yes"))
                //{
    
                MySql.Data.MySqlClient.MySqlConnection oConn1 = new MySql.Data.MySqlClient.MySqlConnection(WebConfigurationManager.ConnectionStrings["filesystem"].ConnectionString);
    
                oConn1.Open();
    
    
                MySql.Data.MySqlClient.MySqlCommand command1 =
                    new MySql.Data.MySqlClient.MySqlCommand("delete from login where USERNAME=?user;", oConn1);
                command1.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?user", MySql.Data.MySqlClient.MySqlDbType.VarChar, 500));
                command1.Parameters[0].Value = (string)DropDownList1.SelectedValue;
    
                command1.ExecuteNonQuery();
                oConn1.Close();
    
    
                oConn1.Open();
                MySql.Data.MySqlClient.MySqlCommand command2 =
                   new MySql.Data.MySqlClient.MySqlCommand("delete from usefiles where USERNAME=?user;", oConn1);
                command2.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?user", MySql.Data.MySqlClient.MySqlDbType.VarChar, 500));
                command2.Parameters[0].Value = (string)DropDownList1.SelectedValue;
    
                command2.ExecuteNonQuery();
                oConn1.Close();
                System.IO.Directory.Delete(Server.MapPath(".") + "\\USERFOLDERS\\" + DropDownList1.SelectedValue);
    
                // "Delete" the row 
                //DeleteResults.Text += string.Format( "This would have deleted ProductID {0}<br />", productID);
                
                GridView1.DataBind();
    
                DropDownList1.Items.Clear();
                DropDownList1.DataBind();
               string a = "a";
                Session["status"] = a;
                Label4.Text = (string)Session["status"];
                Panel1.Visible = false;
    
            }
            catch (Exception exc)
            {
                Response.Write("<script tyep='text/javascript'>alert('Button2_Click<br/>" + exc.Message + "');</script>");
            }
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Its good that you used a try catch block. Its bad that you didn't use a few. Try more debugging and report back. Thanks.

    Comment

    Working...