Unable to resolve this error[There is already an open DataReader associated with this Command which must be closed first]

There is already an open DataReader associated with this Command which must be closed first......
Please help.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Net;

namespace housing1
{
    public partial class admin_action : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                HiddenFieldS2.Value = "Updated";
                HiddenFieldS1.Value = "Pending";
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
                SqlDataAdapter da = new SqlDataAdapter("Select Flat from User_Complain where Status='"+HiddenFieldS1.Value+"'", conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                DropDownListFN.DataSource = dt;
                DropDownListFN.DataTextField = "Flat";
                DataBind();

            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            conn.Open();

            String str = "select Complain_Name ,Description from User_Complain where Flat='" + DropDownListFN.Text.Trim() + "' and Complain_Id='"+TextBoxID.Text+"'";
            SqlCommand comm = new SqlCommand(str, conn);
            SqlDataReader reader = comm.ExecuteReader();
            if (reader.Read())
            {
                TextBoxTOP.Text = reader["Complain_Name"].ToString();
                TextBoxD.Text = reader["Description"].ToString();
               // HiddenFieldM.Value=reader[""]
                reader.Close();
            }

            String str1 = "select Email from Primary_Member where Flat='" + DropDownListFN.Text.Trim() + "'";
            SqlCommand comm1 = new SqlCommand(str1, conn);
            SqlDataReader reader1 = comm1.ExecuteReader();
            if (reader1.Read())
            {

                HiddenFieldM.Value = reader1["Email"].ToString();
                reader1.Close();
            }
            conn.Close();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {

                var messagefrom = "nidhi@indweb.com";
                var toAddress = HiddenFieldM.Value;
                string messageBody = TextBoxAT.Text;
                string fromPassword = "nid100";
                var subject = "Subject";
                var client = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(messagefrom, fromPassword)
                };

                using (var msg = new MailMessage(messagefrom, toAddress)
                {
                    Subject = subject,
                    Body = messageBody
                }
                )
                {
                    client.Send(msg);
                }
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
                conn.Open();
                String insertQuery1 = "insert into Admin_Action ( Flat ,Complain_Name , Description, Action_Performed , Status) values(  @flat , @cname , @des ,@action , @status)";
                SqlCommand com = new SqlCommand(insertQuery1, conn);
                com.Parameters.AddWithValue("@cname", TextBoxTOP.Text);
                com.Parameters.AddWithValue("@flat", DropDownListFN.SelectedValue);
                com.Parameters.AddWithValue("@des", TextBoxD.Text);
                com.Parameters.AddWithValue("@action", TextBoxAT.Text);
                com.Parameters.AddWithValue("@status", "");
                com.ExecuteNonQuery();
                

                
                String updateQuery = "update User_Complain set  Status= '" + HiddenFieldS2.Value + "' where Flat='" + DropDownListFN.SelectedValue + "'";
                SqlCommand com1 = new SqlCommand(updateQuery, conn);
                com1.ExecuteNonQuery();
                conn.Close();
                
     
                
                Response.Write("mail send");
            }

            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

       

       
    }
}

Open in new window

Sukesh ShuklaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naitik GamitSoftware DeveloperCommented:
Set MultipleActiveResultSets=True in web.config will solve your problem.

You can also try to create second connection to same database maybe solves the problem.
0
Éric MoreauSenior .Net ConsultantCommented:
Yes MARS is the solution. Check http://emoreau.com/Entries/Articles/2006/11/MARS-and-Asynchronous-ADONet.aspx for more details.
0
Gary DavisDir Internet SvcsCommented:
Put the Close() call outside the "if" block.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Sukesh ShuklaAuthor Commented:
where exactly do we write MultipleActiveResultSets=True in web.config file
0
Éric MoreauSenior .Net ConsultantCommented:
it is an attribute of your database connection string
0
Naitik GamitSoftware DeveloperCommented:
In web.config you can add MultipleActiveResultSets=True in connection string.

Look at this link for example:
http://stackoverflow.com/questions/15732642/how-to-enable-multipleactiveresultsets
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.