1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Crystal reports

Discussion in 'C#' started by isa, Sep 23, 2006.

  1. isa

    isa New Member

    Joined:
    Sep 22, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Can you clarify your problem a bit more as I could not get you?
     
  3. isa

    isa New Member

    Joined:
    Sep 22, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Sep 26, 2006
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    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.
     
  5. isa

    isa New Member

    Joined:
    Sep 22, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    i m using CR 10 and i didn't find any option for this anyways thanx . Let me check again
     
  6. GIC

    GIC New Member

    Joined:
    Jan 30, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Jan 30, 2007
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    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.
     
  8. GIC

    GIC New Member

    Joined:
    Jan 30, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 ?
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Here is the link [thread=168]Before you make a query[/thread].

     
  10. GIC

    GIC New Member

    Joined:
    Jan 30, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 ?
     
  11. GIC

    GIC New Member

    Joined:
    Jan 30, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    And of course, both ds2 and ds3 are instanced as new DataSet() before use. Sorry for the omission.
     

Share This Page