Crystal reports

isa
Newbie Member
23Sep2006,11:29   #1
isa's Avatar
Hello everyone,I have been working with the reports. but the problem lies when the reports are being displayed. IT IS PROMTING FOR THE PASSWORD EVERY TIME I DISPLAY THE REPORTS.Can you tell me how to avoid this.

Its very urgent. Please find time for me.

thanks in advance.
Go4Expert Founder
25Sep2006,10:35   #2
shabbir's Avatar
Can you clarify your problem a bit more as I could not get you?
isa
Newbie Member
26Sep2006,10:30   #3
isa's Avatar
Whenever my report run its displayes a window in which it asking abt User, Password of the database Sqlserver 2000. i dont want to do this at run time i req whenever i run my report it directly shows the record not asking me abt Login n password of the database. for this i used the following coding in the page load but nothing happens it gaves error
"" invalid report file path "",
here is the code::

Code:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
    ReportDocument rd = new ReportDocument();

        protected void Page_Load(object sender, EventArgs e)
    {
        
       rd.SetDatabaseLogon("saima", "allah", "VSDC", "DANCOM");
        string reportpath = Server.MapPath("CrystalReport.rpt");
   }
}
plz reply me with some solution as i m stuck

Last edited by shabbir; 26Sep2006 at 10:41.. Reason: Code formating.
Go4Expert Founder
26Sep2006,10:42   #4
shabbir's Avatar
There is an option in the menu where you can have the option of Save Password so that it does not ask each time. I dont have the CR installed on my pc right now so could not tell you the exact menu location.
isa
Newbie Member
26Sep2006,11:02   #5
isa's Avatar
i m using CR 10 and i didn't find any option for this anyways thanx . Let me check again
GIC
Newbie Member
30Jan2007,08:31   #6
GIC's Avatar
In my opinion, working with DataAdapters and DataSets is more flexible and more accurate.

Anyway, I don't really know your way of doing, but with a proper connectionString it works fine for my needs. Here is an instance:
Code:
string conStr = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=UserPassword";
SqlConnection con;
SqlDataAdapter da;
ReportDocument rd;
DataSet ds;

try
{
       ds = new DataSet();
       con = new SqlConnection(conStr);
       rd = new ReportDocument();

       string sql = "SELECT * FROM TABLE";
       da = new SqlDataAdapter(sql, con);
       da.Fill(ds, "DataTableName");
       rd.SetDataSource(ds);
}
catch(Exception ex)
{
       throw new Exception("Internal error: " +ex.Message);
}
finally
{
       rd.Close();
       if(ds != null) ds.Dispose();
       if(da != null) da.Dispose();
}
This way, it works fine for me. You may also prefer to use the TableLogOnInfo object.

Hope this helps.

Last edited by shabbir; 30Jan2007 at 14:22.. Reason: Code formating.
Go4Expert Founder
30Jan2007,14:23   #7
shabbir's Avatar
GIC, welcome to the forums and I have edited your post to include the code into the code block so that its easier to read.
GIC
Newbie Member
30Jan2007,20:38   #8
GIC's Avatar
Thank you Shabbir,

How do I put the code within a code block, as you call it, so that the posted code may be easier to read ?
Go4Expert Founder
30Jan2007,20:46   #9
shabbir's Avatar
Here is the link Before you make a query.

Quote:
7) Use code tags. Use the appropriate code tag (e.g. [ php][/php ] and [ code][/code ]) to make your code easier to read. See BB Code Section for [Code]
GIC
Newbie Member
31Jan2007,00:28   #10
GIC's Avatar
I have a little problem when trying to create my report dynamically.

First, let's say that my report contains two subreport sections. Then, I try to make it available to my Windows Application, but I get this error at runtime:

"Unable to find the report in the manifest resources."

Here is how I load my report.

Code:
ReportDocument rd = new ReportDocument();

SqlConnection con = new SqlConnection(properlyDefinedConnectionString);
SqlDataAdapter da;
DataSet ds1;
DataSet ds2;
DataSet ds3;

rd.Load(this.reportPath + this.reportName);

try
{
       ds1 = new Dataset();

       string cmdTxt = "SELECT * FROM Table1";

       da = new SqlDataAdapter(cmdTxt, con);
       // Table1View being the name of the datasource within the report.
       da.Fill(ds1, "Table1View"); 
       rd.SetDataSource(ds);

       cmdTxt = "SELECT * FROM Table2";

       da.Dispose();
       da = new SqlDataAdapter(cmdTxt, con);
       da.Fill(ds2, "Table2View");

       cmdTxt = "SELECT * FROM Table3";

       da.Dispose();
       da = new SqlDataAdapter(cmdTxt, con);
       da.Fill(ds3, "Table3View");

       foreach(Section s in rd.ReportDefinition.Sections)
              foreach(ReportObject ro in s.ReportObjects)
                     if(ro.Kind == ReportObjectKind.SubreportObject)
                     {
                            ReportDocument srd = new ReportDocument();
                            
                            SubreportObject srdObj = (SubreportObject)ro;
                            switch(srdObj.OpenSubreport(srdObj.SubreportName).Name)
                            {
                                   case "Table2View":
                                          {
                                                 srdObj.SetDataSource(ds2);
                                                 break;
                                          }
                                   case "Table3View":
                                         {
                                                srdObj.SetDataSource(ds3);
                                                break;
                                         }
                            }
                     }
}
catch(Exception ex)
{
       throw new Exception("Internal Error: " + ex.Message);
}
finally
{
       rd.Close();
       if(ds1 != null) ds1.Dispose();
       if(ds2 != null) ds2.Dispose();
       if(ds3 != null) ds3.Dispose();
       if(da != null) da.Dispose();       
}
I read a little about my problem, and it always conduct me to verify what version of Crystal Reports do I have. Is it the bundled or the full version ? As for now, it seems to be the bundled version.

I use Visual Studio 2005 Team Suite Edition with Crystal Reports for Visual Studio 2005.

Please, let's consider that I already have defined my datasets as new items within my project. However, I did not link those to my SQL Server 2005, but only constructed "fake" data tables to match the fields' name of my SQL Query with the above-suggested code.

Any idea, anyone ? Should I install another version of Crystal Reports in order to make it work ?