Server Error in '/' Application. The ConnectionString property has not been initialized. 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.InvalidOperationException: The ConnectionString property has not been initialized. Source Error: Line 118: SqlDataAdapter dAdapter = new SqlDataAdapter(command); Line 119: command.Parameters.AddWithValue("@Email", Email); Line 120: connection.Open(); Line 121: dAdapter.Fill(dsPwd); Line 122:
<pre lang="c#">public ActionResult ForgotPassword(User s) { using (userEntities2 db = new userEntities2()) { string Email = Request.Form["Email"]; string Msg = Request.Form["Message"]; string strConnection = ConfigurationSettings.AppSettings["userEntities2"]; string strSelect = "SELECT UserName,Password FROM user WHERE Email = @Email"; SqlConnection connection = new SqlConnection(strConnection); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = strSelect; DataSet dsPwd = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(command); command.Parameters.AddWithValue("@Email", Email); connection.Open(); dAdapter.Fill(dsPwd); connection.Close(); if (dsPwd.Tables[0].Rows.Count > 0) { string MailingAddress = ConfigurationManager.AppSettings["MailingAddress"].ToString(); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(MailingAddress, Email); SmtpClient client = new SmtpClient(); message.Subject = "Forget Password"; message.IsBodyHtml = true; message.Body = "Username: " + dsPwd.Tables[0].Rows[0]["UserName"] + "<br><br>Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br><br>"; client.Host = "smtp.mail.yahoo.com"; client.Port = 587; client.Credentials = new System.Net.NetworkCredential ("email", "password"); client.EnableSsl = true; client.Send(message); Response.Write("<script LANGUAGE='JavaScript'>alert('Email has Sent')</script>"); } else { Response.Write("<script LANGUAGE='JavaScript'>alert('Email Not Register')</script>"); } return View(s); } }</pre>
using
command.Connection = connection; SqlDataAdapter dAdapter = new SqlDataAdapter(command);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)