Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

"The report filename was empty" rears its ugly head again

$
0
0

I know this is a common error people run into, but the previous threads I've found here haven't helped me discover the problem yet. I've got a web page using the CrystalReportViewer which has been working fine for several reports that have parameters where I'm allowing the viewer to provide the parameter prompts to the user.  My latest report has no parameters and I get this error on my first attempt to run the report.  However, if I then refresh the browser the report viewer displays the data correctly.  What's going on?  I saw on another thread where it was suggested that the code to load the report be moved from Page_Load to Page_Init, but I didn't see any behavioral differences with any of my reports when I tried that.  I'll post my code below.

 

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!Page.IsPostBack)

            {

                this.crviewer1.ParameterFieldInfo.Clear();

 

                switch (Request.QueryString["rpt"])

                {

                    case "EmpUtilByWeek":

                        // Has parameters

                        ConfigureCrystalReports("~/Reports/EmpUtilByWeek.rpt", Global.MAS_ConnectionString);

                        break;

                    case "EmpUtilByMonth":

                        // Has parameters

                        ConfigureCrystalReports("~/Reports/EmpUtilByMonth.rpt", Global.MAS_ConnectionString);

                        break;

                    case "OTHoursCostRev":

                        // Has parameters

                        ConfigureCrystalReports("~/Reports/OTHoursCostRev.rpt", Global.MAS_ConnectionString);

                        break;

                    case "AROpenAging":

                        // No parameters

                        ConfigureCrystalReports("~/Reports/AROpenAging.rpt", Global.MAS_ConnectionString);

                        break;

                    default:

                        break;

                }

            }

        }

 

        private void ConfigureCrystalReports(string ReportFile, string ConnectionString)

        {

            // Set Crystal report source

            CrystalDecisions.Web.Report cr = new CrystalDecisions.Web.Report();

            cr.FileName = Server.MapPath(ReportFile);

            this.crsource1.Report = cr;

 

            // Get database logon info from web.config

            CrystalDecisions.Shared.TableLogOnInfo logon = GetReportLogonInfo(ConnectionString);

            this.crviewer1.LogOnInfo.Add(logon);

        }

 

        private CrystalDecisions.Shared.TableLogOnInfo GetReportLogonInfo(string ConnectionString)

        {

            CrystalDecisions.Shared.TableLogOnInfo logon = new CrystalDecisions.Shared.TableLogOnInfo();

            CrystalDecisions.Shared.ConnectionInfo connInfo = new CrystalDecisions.Shared.ConnectionInfo();

 

            string[] conn = ConnectionString.Split(';');

            foreach (string s in conn)

            {

                string[] keyVal = s.Split('=');

                switch (keyVal[0].ToLower())

                {

                    case "data source":

                        connInfo.ServerName = keyVal[1];

                        break;

                    case "initial catalog":

                        connInfo.DatabaseName = keyVal[1];

                        break;

                    case "user id":

                        connInfo.UserID = keyVal[1];

                        break;

                    case "password":

                        connInfo.Password = keyVal[1];

                        break;

                }

            }

 

            logon.ConnectionInfo = connInfo;

            return logon;

        }

 

OK, here's one thing I discovered... the statement this.crviewer1.ParameterFieldInfo.Clear(); seems to be the culprit.  When I comment this out, my parameter-free report displays fine on the first attempt.  However, the unwanted side-effect is that my other reports will retain their initial parameters if I try to run them a second time, which is the reason I used the Clear() method in the first place.  So, I then thought the fix would be to call Clear() only for my parameterized reports like this:

 

                if (this.crviewer1.ParameterFieldInfo.Count > 0)

                    this.crviewer1.ParameterFieldInfo.Clear();

 

But, alas, this once again makes my parameter-free report fail on the first attempt.  It appears that the act of evaluating the this.crviewer1.ParameterFieldInfo object is enough to cause this problem, which I find most peculiar.  So the only solution I've come up with is to move my Clear() statement into each of the case statements where I have a parameterized report.  This is a very non-elegant solution in my opinion, so I'd really like to understand why it behaves this way and hopefully find a better way to handle both parameterized and parameter-free reports.


Viewing all articles
Browse latest Browse all 3636

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>