I am trying to mail crystal report as pdf, on button click. Thought the page is working good & the pdf is getting mail when i am working on local end. But when i try the same code on production server. I am getting errors "[Database Vendor Code: 17 ]Failed to open the connection." Which possibly is due to failed databse - crystal report connectivity. Please let me know what changes do i have to apply in order to make the report work on production server too.
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Quotations";
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataTable datatable = new DataTable();
da.Fill(datatable); // getting value according to imageID and fill dataset
ReportDocument crystalReport = new ReportDocument(); // creating object of crystal report
crystalReport.Load(Server.MapPath("~/CrystalReport.rpt")); // path of report
crystalReport.SetDataSource(datatable); // binding datatable
using (MailMessage mm = new MailMessage("******@gmail.com", "********@gmail.com"))
{
mm.Subject = "IEMCO Quotaion ";
mm.Body = "Greeting,<br/><br/>Thanks for choosing IEMCO as your business partner.<br/><br/>As discussed, the quotation of requested product is attached herewith this mail.<br/><br/> Please have a look & let us know your final requirement.<br/><br/>";
mm.Attachments.Add(new Attachment(crystalReport.ExportToStream(ExportFormatType.PortableDocFormat), "Report.pdf"));
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
NetworkCredential credential = new NetworkCredential();
credential.UserName = "*******@gmail.com";
credential.Password = "#####";
smtp.UseDefaultCredentials = true;
smtp.Credentials = credential;
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(mm);
Label1.Visible = true;
Label1.Text = "Data Sent";
}
}
Is there any tutorial or guide which can help me process the crystal report on server. What all steps do i have to perform in order to make the crystal report server ready.
Thanks