[Solved] Compiler Error Message: CS0135: con conflicts with the declaration in C#

RichardSa
 
on Jul 12, 2022 03:45 AM
393 Views

I treid to reset password in my application but got an error below

Server Error in '/' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0135: 'con' conflicts with the declaration 'ResetPassword.con' Source Error:

 
Line 87:                     Hyper.ForeColor = Color.Green;
Line 88:                 }
Line 89:                 con.Close();
Line 90:          }
Line 91:             else

Code

public partial class ResetPassword : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=N1NWPLSK12SQL-v02.shr.prod.ams1.secureserver.net;Initial Catalog=Quirver_DB;Persist Security Info=True;User ID=quirverT;Password=************");
    String GUIDvalue;
    DataTable dt = new DataTable();
    int Uid;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection("Data Source=N1NWPLSK12SQL-v02.shr.prod.ams1.secureserver.net;Initial Catalog=Quirver_DB;Persist Security Info=True;User ID=quirverT;Password=**********"))
        {
            GUIDvalue = Request.QueryString["Uid"];
            if (GUIDvalue != null)
            {
                SqlCommand cmd = new SqlCommand("select * from ForgotPassRequests where id='" + GUIDvalue + "'", con);
                con.Open();
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                sda.Fill(dt);
                if (dt.Rows.Count != 0)
                {
                    Uid = Convert.ToInt32(dt.Rows[0][1]);
                }
                else
                {
                    Labelmsg.Text = "Your Password reset Link is Expired or Invalid !";
                    Labelmsg.ForeColor = Color.Red;
                }
            }
            else
            {
                Response.Redirect("login.aspx");
            }
        }

        if (!IsPostBack)
        {
            if (dt.Rows.Count!=0)
            {
                LblEmail.Visible = true;
                tbEmailId.Visible = true;
                Label1.Visible = true;
                TextBox1.Visible = true;
                Button1.Visible = true;
            }
            else
            {
                Labelmsg.Text = "Your Password reset Link is Expired or Invalid !";
                Labelmsg.ForeColor = Color.Red;
                Labelmsg.Visible = true;
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if(tbEmailId.Text != "")
        {
           if (tbEmailId.Text == TextBox1.Text)
           {
                using (SqlConnection con = new SqlConnection("Data Source=N1NWPLSK12SQL-v02.shr.prod.ams1.secureserver.net;Initial Catalog=Quirver_DB;Persist Security Info=True;User ID=quirverT;Password=***********"))
                {
                    con.Open();
                    string UpdateLog = @"UPDATE Users SET pass=@pass WHERE Uid = @Uid";
                    using (SqlCommand cmd = new SqlCommand(UpdateLog, con))
                    {
                        cmd.Parameters.AddWithValue("@pass", tbEmailId.Text.Trim());
                        cmd.Parameters.AddWithValue("@Uid", Uid);
                        cmd.ExecuteNonQuery();
                    }
                    SqlCommand cmd2 = new SqlCommand("DELETE FROM ForgotPassRequests WHERE Uid='" + Uid + "'", con);
                    cmd2.ExecuteNonQuery();
                    Hyper.Text = "Password Successfully changed Click to Login";
                    Hyper.Visible = true;
                    Hyper.ForeColor = Color.Green;
                }
                con.Close();
         }
            else
            {
                confirm.Text = "Passwords don't match!";
                confirm.ForeColor = Color.Red;
                errlabel.Visible = false;
            }
        }
        else
        {
            errlabel.Text = "Enter new password";
            errlabel.ForeColor = Color.Red;
            confirm.Visible = false;
            errlabel.Visible = true;
        }
    }
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 12, 2022 03:45 AM
RichardSa says:
SqlConnection con = new SqlConnection("Data Source=N1NWPLSK12SQL-v02.shr.prod.ams1.secureserver.net;Initial Catalog=Quirver_DB;Persist Security Info=True;User ID=quirverT;Password=************");

Remove the above line.

Inside the PageLoad and Button1_Click event you are defining SqlConnection again. So it is not required.

If you want to keep it then you need to provide different name to the variable.