Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello all

I am facing an error with my web application, that when you want to register as new user and after your finish filling up the your personal information and click on the button its take long time to process and at the end its shown the below error message. So can some one help to fix this error please

C#
protected void btnSave_Click(object sender, EventArgs e)
        {
            string LogoFileExtention = System.IO.Path.GetExtension(logoFileUpload.FileName);
            string BizImg1FileExtention = System.IO.Path.GetExtension(FileUploadimage1.FileName);
            string BizImg2FileExtention = System.IO.Path.GetExtension(FileUploadImage2.FileName);
            string BizImg3FileExtention = System.IO.Path.GetExtension(FileUploadImage3.FileName);
            string PersImgFileExtention = System.IO.Path.GetExtension(persimgFileUpload1.FileName);

            if (UsrTypeDrDo.SelectedValue == "null")
            {
                alertpanel.Visible = true;
                selectusrtype.Text = "Please select user type";
            }

            if (statedrdolst.Items.Count == 0)
            {
                alertpanel.Visible = true;
                StateReqLbl.Text = "Please select state where you live.";
            }

            if (citiesdrdolst.Items.Count == 0)
            {
                alertpanel.Visible = true;
                StateReqLbl.Text = "Please select state where you live.";
            }



            else
            {

                HttpCookie cookie = Request.Cookies.Get("Location");
                string Location = string.Empty;
                SqlConnection cn = new SqlConnection(sc);
                SqlCommand cmd = new SqlCommand();
                Location = cookie.Value;

                if (CheckBox1.Checked)
                {
                    if (logoFileUpload.HasFile || FileUploadimage1.HasFile || FileUploadImage2.HasFile || FileUploadImage3.HasFile || persimgFileUpload1.HasFile)
                    {


                        var files = new[] { LogoFileExtention, BizImg1FileExtention, BizImg2FileExtention, BizImg3FileExtention, PersImgFileExtention };
                        files = files.Where(s => !string.IsNullOrEmpty(s)).ToArray();
                        var extensions = new[] { ".jpg", ".png" };
                        if ((files.Except(extensions).Count()) <= 0)
                        {
                                string sqlstatment = @"INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, Img, Logo,
RegDate,Address, UsrType,BizCateg,BizSubCateg, CompNme, Facebook, GooglePlus, Twitter, Website, image1, image2, image3) VALUES 
(@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@Img,@Logo,@RegDate,@Address,@UsrType,@BizCateg,@BizSubCateg,
@CompNme,@Facebook,@GooglePlus,@Twitter,@Website,@image1,@image2,@image3)";

                                cmd.Connection = cn;
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = sqlstatment;

                                //Insert the parameters first
                                cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
                                cmd.Parameters.AddWithValue("@FN", fnbox.Text);
                                cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
                                cmd.Parameters.AddWithValue("@Password", passtxtbx1.Text);
                                cmd.Parameters.AddWithValue("@RePass", passtxtbx2.Text);
                                cmd.Parameters.AddWithValue("@Email", emailbox.Text);
                                cmd.Parameters.AddWithValue("@Country", cookie.Value);
                                cmd.Parameters.AddWithValue("@State", statedrdolst.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@City", citiesdrdolst.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@Post", postbox.Text);
                                cmd.Parameters.AddWithValue("@CompNme", CompNmeTxtBox.Text);
                                cmd.Parameters.AddWithValue("@RegDate", DateTime.Now);
                                cmd.Parameters.AddWithValue("@Address", regaddrstxtbx.Text);
                                cmd.Parameters.AddWithValue("@UsrType", UsrTypeDrDo.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@Facebook", FacebookUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@GooglePlus", TwitUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@Twitter", GPlusUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@Website", WeblinkUsrtxtbox.Text);

                                string imgnouser = "/images/general/nouser.jpg";

                                if (FileUploadimage1.HasFile)
                                {
                                    cmd.Parameters.AddWithValue("@image1", FileUploadimage1.FileName);
                                    FileUploadimage1.SaveAs(Server.MapPath("~/images/BizImgs/" + FileUploadimage1.FileName));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@image1", imgnouser);
                                }


                                if (FileUploadImage2.HasFile)
                                {
                                    cmd.Parameters.AddWithValue("@image2", FileUploadImage2.FileName);
                                    FileUploadImage2.SaveAs(Server.MapPath("~/images/BizImgs/" + FileUploadImage2.FileName));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@image2", imgnouser);
                                }


                                if (FileUploadImage3.HasFile)
                                {
                                    cmd.Parameters.AddWithValue("@image3", FileUploadImage3.FileName);
                                    FileUploadImage3.SaveAs(Server.MapPath("~/images/BizImgs/" + FileUploadImage3.FileName));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@image3", imgnouser);
                                }

                                if (persimgFileUpload1.HasFile)
                                {
                                    cmd.Parameters.AddWithValue("@Img", persimgFileUpload1.FileName);
                                    persimgFileUpload1.SaveAs(Server.MapPath("~/images/users/" + persimgFileUpload1.FileName));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@Img", imgnouser);
                                }


                                if (logoFileUpload.HasFile)
                                {
                                    cmd.Parameters.AddWithValue("@Logo", logoFileUpload.FileName);
                                    logoFileUpload.SaveAs(Server.MapPath("~/images/Logos/" + logoFileUpload.FileName));
                                }

                                else
                                {
                                    cmd.Parameters.AddWithValue("@Logo", imgnouser);
                                }



                                if (BizCateDDL.SelectedIndex < 0)
                                {
                                    cmd.Parameters.AddWithValue("@BizCateg", DBNull.Value);
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@BizCateg", BizCateDDL.SelectedItem.Value);
                                }

                                if (SubCatBizDDL.SelectedIndex < 0)
                                {
                                    cmd.Parameters.AddWithValue("@BizSubCateg", DBNull.Value);
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@BizSubCateg", SubCatBizDDL.SelectedItem.Value);
                                }
                            

                                if (!string.IsNullOrEmpty(UsrNme.Text))
                                {
                                    Lblcheckusername.Text = "User Name Already Exist";
                                    Lblcheckusername.ForeColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    Lblcheckusername.Text = "User Name Available";
                                    Lblcheckusername.ForeColor = System.Drawing.Color.Green;
                                }

                               
                               

                                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                                DataSet ds = new DataSet();
                                ad.SelectCommand = cmd;
                                ad.Fill(ds);
                                Session["UsrNme"] = UsrNme.Text;

                              
                            
                                Response.Redirect("User panel.aspx");
                            }

                        else
                        {
                            alertpanel.Visible = true;
                            imagesformtLbl.Text = "Images should be in .JPG or .PNG format only";
                            return;
                        }

                        
                      
                    }

                    else
                    {
                         string sqlstatment = @"INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, 
RegDate,Address, UsrType,BizCateg,BizSubCateg, CompNme, Facebook, GooglePlus, Twitter, Website) VALUES 
(@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@RegDate,@Address,@UsrType,@BizCateg,@BizSubCateg,
@CompNme,@Facebook,@GooglePlus,@Twitter,@Website)";

                                cmd.Connection = cn;
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = sqlstatment;

                                //Insert the parameters first
                                cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
                                cmd.Parameters.AddWithValue("@FN", fnbox.Text);
                                cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
                                cmd.Parameters.AddWithValue("@Password", passtxtbx1.Text);
                                cmd.Parameters.AddWithValue("@RePass", passtxtbx2.Text);
                                cmd.Parameters.AddWithValue("@Email", emailbox.Text);
                                cmd.Parameters.AddWithValue("@Country", cookie.Value);
                                cmd.Parameters.AddWithValue("@State", statedrdolst.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@City", citiesdrdolst.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@Post", postbox.Text);
                                cmd.Parameters.AddWithValue("@CompNme", CompNmeTxtBox.Text);
                                cmd.Parameters.AddWithValue("@RegDate", DateTime.Now);
                                cmd.Parameters.AddWithValue("@Address", regaddrstxtbx.Text);
                                cmd.Parameters.AddWithValue("@UsrType", UsrTypeDrDo.SelectedItem.Text);
                                cmd.Parameters.AddWithValue("@Facebook", FacebookUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@GooglePlus", TwitUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@Twitter", GPlusUsrTXTBX.Text);
                                cmd.Parameters.AddWithValue("@Website", WeblinkUsrtxtbox.Text);



                                if (BizCateDDL.SelectedIndex < 0)
                                {
                                    cmd.Parameters.AddWithValue("@BizCateg", DBNull.Value);
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@BizCateg", BizCateDDL.SelectedItem.Value);
                                }

                                if (SubCatBizDDL.SelectedIndex < 0)
                                {
                                    cmd.Parameters.AddWithValue("@BizSubCateg", DBNull.Value);
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@BizSubCateg", SubCatBizDDL.SelectedItem.Value);
                                }
                               

                                if (!string.IsNullOrEmpty(UsrNme.Text))
                                {
                                    Lblcheckusername.Text = "User Name Already Exist";
                                    Lblcheckusername.ForeColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    Lblcheckusername.Text = "User Name Available";
                                    Lblcheckusername.ForeColor = System.Drawing.Color.Green;
                                }

                               
                                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                                DataSet ds = new DataSet();
                                ad.SelectCommand = cmd;
                                ad.Fill(ds);
                                Session["UsrNme"] = UsrNme.Text;

                             

                                Response.Redirect("User panel.aspx");
                    }

                }
                    else
                    {
                        Label1.Text = "please check the box to continue";
                    }

                }

            }


Server Error in '/' Application.

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.171.108:587

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.171.108:587

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.171.108:587]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +464

[WebException: Unable to connect to the remote server]
   System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6647364
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +307
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +19
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +324
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
   System.Net.Mail.SmtpClient.GetConnection() +44
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1554

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
   beravoSV.Registration.btnSave_Click(Object sender, EventArgs e) +6758
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724<pre>&lt;/pre&gt;</pre>
Posted
Comments
phil.o 22-Oct-15 9:30am    
The issue you describe and the code sample you give do not match: the error you are having is an SMTP problem. This is not a connection problem to your database, it's a connection problem to your mail server on port 587 (secure SMTP).
F-ES Sitecore 22-Oct-15 9:42am    
The problem is when you try and send email, which isn't in the code you've posted, neither is this a problem we can fix. Make sure your web server can communicate with your smtp server as there will be a config or network issue preventing them communicating.
Krunal Rohit 22-Oct-15 10:07am    
[SmtpException: Failure sending mail.]
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.171.108:587.

Error is self-explanatory. It's somehow related to sending mail from your application as exception suggests. It is getting failed because server is not responding.
And I didn't see any code related to mail sending.
I'd suggest you to put the breakpoint and use the debugger, find out what the issue is.
If the issue still persist, post your query on forum.

-KR

1 solution

Seems like a mail sending issue. So I suggest you to debug and check the line which is causing the issue.

Pasting all the codes don't help us. Because we can't predict the line of issue. If you narrow down the problem to couple of line of codes, then it would definitely help us suggesting you solutions. But before that, try to debug yourself and find out the cause.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900