Before I can proceed with this tutorial I assume that the reader has already developed a report in crystal and has loaded it in crystal report viewer control. Running the website and the report page prompts the user with something like this.
Now we don’t want to give login information every time we try to run this report. Its annoying . so what we need to do is to do something with the help of which we can get our report perfectly without this stupid prompt. To solve this problem we will provide the login information programmatically so that our report page don’t prompt us for it. To solve the problem I have done the following. Add the following code to the top of the report page.
using CrystalDecisions; using CrystalDecisions.CrystalReports; usingCrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared;
Now in the Page_Load() event write the following code. Or we can write this code in any other function and call it when we want to provide the login information.
Now in the Page_Load() event write the following code. Or we can write this code in any other function and call it when we want to provide the login information.
ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath("myReport.rpt")); rpt.SetDatabaseLogon("myUserLogin", "mypassword", @"Server", "Database"); CrystalReportViewer1.ReportSource = rpt;
Save the page and run the report. This time it will not prompt for the stupid logon information. If some one wants a very basic article on how to create a report and how to call it in asp.net. plz leave your comments . I will write a basic tutorial for creating a crystal report and calling it from asp.net.
Note:- Plz leave ur comments if this article was helpful.
Thanks.
32 comments
Comments feed for this article
May 22, 2011 at 1:52 pm
smaa
still have the same problem the server and the user exist but the field of database and pass are empty and don’t accept typing why???
May 22, 2011 at 3:12 pm
mirnauman
can u explain ur problem in a lil detail, and also if possible post ur code as well. also tell me do u want to use the default created logon prompt and u r not able to type in it. or u just want to get rid of it.
December 21, 2012 at 7:21 am
kavya
I am also having the same problem as smaa… please tell me how to get rid of that logon prompt..
Thanks in advance
December 22, 2012 at 6:31 pm
Mir
can u tell me the following
your machine name,
your server name that u give in the prompt,
your db name,
your user name that u use to login to the db,
and your password for that user.
April 2, 2012 at 7:01 pm
Ankur Tangirala
You saved my life with this workaround. Thanks a lot!!!
This is a problem a lot are having with service pack 2.
April 4, 2012 at 3:43 am
Mir
Thanks,
n thanks again for pointing out the service pack 2 thing.
April 22, 2012 at 8:03 am
sayanta das
thanks…it works…
June 13, 2012 at 7:16 am
Abhishek Divekar
it not solved my problem. We are alwase facing same window while running crystal reports. I installed application on two server. In one server application and reports run perfectly but on one server login window alwase comes. Can you have any solution
September 27, 2012 at 11:55 am
Girija
ya it works
February 22, 2013 at 12:20 am
Hakoo Desai
Hi, this solution is not working for me, it is still asking for Login Prompt.
February 22, 2013 at 4:45 am
Mir
check wat kind of authentication u r using. if u r using windows authentication for sql server than this might not work. I am using mixed mode, where sql server login info is different than the windows login thingi.
February 22, 2013 at 8:11 am
Hakoo
Thanks for your reply. I am using sql server authentication, where I am providing all mandatory details.
February 26, 2013 at 7:39 am
Mir
Than u need to check which .net version u r using and wat kind of libraries it has. there might be a difference there. also check if the user though which u log on to ur computer is administrator or have administrative privileges.
April 25, 2013 at 7:21 am
vivek
Dear sir am using the same type of code using to my source while i execute in local it generate the report successfully after i deployee in iis its show error like unable to incorrect log on paramet like that….i hope pls give me any idea..
my mail id:
technicalexecutive1@oegindia.com
April 25, 2013 at 7:33 am
Mir
U need to check the logon credentials on the server. Also check the permissions what u have on the server.
April 25, 2013 at 7:42 am
vivek
dear mir ..how to check in the permissions and what is credentials?
April 25, 2013 at 7:56 am
Mir
credentials are, ur sqlserver login and password, ur server address like an ip address. if ur development machine and publishing machine is the same u can try localhost, but sometime this wont work for publishing . and ur database name will also be required.
permissions u need to check like right clicking on the folder in ur wwwroot directory, than click properties and than go to security tab. u will find permissions there.
April 25, 2013 at 8:25 am
vivek
k thanks mir i get the report and its as generated thank u very much for ur advice really thanks so much….
April 25, 2013 at 8:35 am
vivek
mir in that i want to get in pdf format how to writ code for that pls
April 25, 2013 at 9:40 am
Mir
R u using crystal reports or reporting services
April 25, 2013 at 9:54 am
vivek
am using in visual studio 2005 in that
April 25, 2013 at 10:07 am
Mir
For reports creation what r u using
April 25, 2013 at 10:14 am
vivek
crystal report only mir
April 25, 2013 at 10:30 am
Mir
No coding required. If u r using crystal report viewer control. Just enable the export to PDF button of the control. N it’s done.
April 25, 2013 at 10:38 am
vivek
i send u my source where i want to enable in properties ah? in the properties der no option to enable the pdf
protected void Button1_Click(object sender, EventArgs e)
{
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath(“MR.rpt”));
rpt.SetParameterValue(“MRNO”, ddlmrno.SelectedItem.Text);
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.RefreshReport();
rpt.SetDatabaseLogon(“”, “”, “RAMYA-BD”, “”);
System.IO.MemoryStream oStream; // using System.IO
oStream = (MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer = true;
Response.ContentType = “application/pdf”;
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
April 25, 2013 at 11:14 am
vivek
while i export to like this it showing error like incorrect log on parameter pls guide me
April 26, 2013 at 4:21 am
vivek
mir if i supress the Ostream the report as generat if i put the osteam means it show the error pls correct and give me
April 26, 2013 at 5:33 am
Mir
dear vivek,
to export ur report to pdf you can do something like this. try this.
http://stackoverflow.com/questions/3152198/crystal-report-viewer-export-to-open-a-pdf-after-entering-parameters
check answer 3 for this question.
April 26, 2013 at 6:11 am
vivek
mir i not usign dataset
April 29, 2013 at 5:58 am
vivek
hi mir send ur mail id i send u my code pls correct and give me
April 29, 2013 at 6:16 am
vivek
hi frinds if i comment the oStream = (MemoryStream)reportdocument.ExportToStream(ExportFormatType.PortableDocFormat); this line and Response.BinaryWrite(oStream.ToArray()); this report is generate in IIS but i not get in proper pdf formate pls help me i want to generate in pdf formate pls guide me
public partial class frm_MRPrint : System.Web.UI.Page
{
SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings[“conn”].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
mr();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
MemoryStream oStream;
Response.Clear();
Response.Buffer = true;
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath(“MR.rpt”));
reportdocument.SetDatabaseLogon(“sa”, “Admin123”, “vivek”, “PURCHASE”);
reportdocument.SetParameterValue(“MRNO”, ddlmrno.SelectedItem.Text);
CrystalReportViewer1.ReportSource = reportdocument;
oStream = (MemoryStream)reportdocument.ExportToStream(ExportFormatType.PortableDocFormat);
Response.ContentType = “application/pdf”;
try
{
//write report to the Response stream
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
catch (Exception ex)
{
Label2.Visible = true;
Label2.Text = “ERROR:” + Server.HtmlEncode(ex.Message.ToString());
}
finally
{
//clear stream
oStream.Flush();
oStream.Close();
oStream.Dispose();
}
//in case you want to export it as an attachment use the line below
//crReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, “Your Exported File Name”);
}
public void mr()
{
ddlmrno.Items.Clear();
ListItem frstitem = new ListItem();
frstitem.Text = “- Select -“;
ddlmrno.Items.Add(frstitem);
ddlmrno.SelectedIndex = 0;
Con.Open();
string sql = “”;
sql = “select distinct(MRNO) from dbo.tbl_KKSMR where status=1 order by MRNO asc”;
SqlCommand cmd = new SqlCommand(sql, Con);
SqlDataReader rdr;
try
{
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ListItem newItem = new ListItem();
newItem.Text = rdr[“MRNO”].ToString().Trim();
newItem.Value = rdr[“MRNO”].ToString().Trim();
ddlmrno.Items.Add(newItem);
}
rdr.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cmd.Dispose();
} Con.Close();
}
}
August 29, 2014 at 1:55 pm
trijan
This solution work for me..,
i used a user in my database.,.