Wrox Programmer Forums
|
BOOK: Professional Crystal Reports for VS.NET
This is the forum to discuss the Wrox book Professional Crystal Reports for Visual Studio .NET by David McAmis; ISBN: 9780764544033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Crystal Reports for VS.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2007, 04:49 AM
Registered User
 
Join Date: Oct 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database Connector Error

When I try to generate a report on a production site I am getting the following error:
Database Connector Error: ''Error in File C:\DOCUME~1\ORIEL\IWAM_S~1\LOCALS~1\Temp\Applicati on Stage {BAAA3BC1-2A40-4695-B048-E8C70C38A7FF}.rpt

/// <summary>
    /// Event actioned when the 'Generate' button ispressed
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        OleDbDataReader rdrReports;
        ReportDocument rdReport = new ReportDocument();
        ExportOptions eoReport;
        ParameterFieldDefinitions crParameterFieldDefinitions;
        ParameterFieldDefinition crSartDateParam;
        ParameterFieldDefinition crEndDateParam;
        ParameterDiscreteValue disvStart;
        ParameterDiscreteValue disvEnd;
        ParameterValues crParameter1;
        ParameterValues crParameter2;
        DiskFileDestinationOptions dfdoCRExport;
        Configuration config;
        OleDataHelper helper;
        ConnectionInfo crInfo = new ConnectionInfo();

        string strSQL = string.Empty;
        string strReportFile = string.Empty;
        string strMessage = string.Empty;
        string strFilename = string.Empty;
        string strFilepath = string.Empty;
        string strSubName = string.Empty;
        string strDataPath = string.Empty;
        string strServerName = string.Empty;
        string strProgress = string.Empty;

        int intReportID;
        int intStatus = 0;
        bool blnDatesParam = false;
        bool blnEndDateParam = false;
        string strTemp = string.Empty;

        helper = new OleDataHelper();
        rdrReports = null;

        //set up access to the web config file and its settings
        config = WebConfigurationManager.OpenWebConfiguration(Reque st.ApplicationPath);
        AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings ");

        try
        {
            //Retrieve which report we are dealing with from the drop down list
            intReportID = Convert.ToInt16(ddlTitles.SelectedValue);
            intStatus = Convert.ToInt16(hidStatus.Value);

            strProgress = "Retrieving Report Details";
            //Get information of the report such which parameter data is required
            strSQL = "select * from Q_ReportDetails where Report_ID=" + intReportID.ToString();
            rdrReports = helper.ExecuteReader("Goldmine", strSQL);

            if (rdrReports.HasRows)
            {
                rdrReports.Read();
                strReportFile = "/OrielGold/reports/" + rdrReports.GetString(1);
                blnDatesParam = rdrReports.GetBoolean(2);
                blnEndDateParam = rdrReports.GetBoolean(3);
            }


            //if using the date parameters then check the validitity of inputs
            if (blnDatesParam)
            {
                if (!bdplFrom.ValidDateEntered)
                {
                    strMessage += "From Date is invalid\n";
                }
                else if (bdplFrom.IsNull) // If it's not null, then create Text for Label.
                {
                    strMessage += "From Date is absent\n";
                }
                if (!bdplTo.ValidDateEntered)
                {
                    strMessage += "To Date is invalid\n";
                }
                else if (bdplTo.IsNull) // If it's not null, then create Text for Label.
                {
                    strMessage += "To Date is absent\n";
                }
            }

            if (blnEndDateParam)
            {
                if (!bdplEndDate.ValidDateEntered)
                {
                    strMessage += "End Date is invalid\n";
                }
                else if (bdplEndDate.IsNull) // If it's not null, then create Text for Label.
                {
                    strMessage += "End Date is absent\n";
                }
            }

            //check for validation errors
            if (strMessage.Length > 0)
            {
                strProgress = "Input Validation:";
                throw new ArgumentException(strMessage);
            }

            //Create the report through Crystal Reports
            //rdReport = new ReportDocument();
            strProgress = "Report Load";
            rdReport.Load(Server.MapPath(strReportFile));

            strProgress = "Setting up Connection Info:";
            crInfo.DatabaseName = appSettings.Settings["AccessDB"].Value;
            crInfo.ServerName = appSettings.Settings["AccessDB"].Value;
            crInfo.UserID = ""; // "Goldmine";
            crInfo.Password = ""; // "orielgold";

            strProgress = "Assigning Connection Info, main report:";
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in rdReport.Database.Tables)
            {
                AssignTableConnections(table, crInfo);
            }
            strProgress = "Assigning Connection Info, subreports:";
            foreach(CrystalDecisions.CrystalReports.Engine.Sec tion section in rdReport.ReportDefinition.Sections)
            {
                foreach(CrystalDecisions.CrystalReports.Engine.Rep ortObject reportObject in section.ReportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport = (SubreportObject)reportObject;
                        ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);
                        foreach(CrystalDecisions.CrystalReports.Engine.Tab le table in subDocument.Database.Tables)
                        {
                            AssignTableConnections(table,crInfo);
                        }
                    }
                }
            }

            strProgress = "Setting Report Parameters:";
            //set report parameters
            crParameterFieldDefinitions = rdReport.DataDefinition.ParameterFields;
            if (blnDatesParam)
            {
                crSartDateParam = crParameterFieldDefinitions["Start Date"];
                crEndDateParam = crParameterFieldDefinitions["End Date"];
                crParameter1 = crSartDateParam.CurrentValues;
                crParameter2 = crEndDateParam.CurrentValues;

                disvStart = new ParameterDiscreteValue();
                disvStart.Value = bdplFrom.SelectedDateFormatted;
                disvEnd = new ParameterDiscreteValue();
                disvEnd.Value = bdplTo.SelectedDateFormatted;

                crParameter1.Add(disvStart);
                crParameter2.Add(disvEnd);

                crSartDateParam.ApplyCurrentValues(crParameter1);
                crEndDateParam.ApplyCurrentValues(crParameter2);
            }

            if (blnEndDateParam)
            {
                crEndDateParam = crParameterFieldDefinitions["End Date"];
                crParameter2 = crEndDateParam.CurrentValues;

                disvEnd = new ParameterDiscreteValue();
                disvEnd.Value = bdplEndDate.SelectedDateFormatted;

                crParameter2.Add(disvEnd);
                crEndDateParam.ApplyCurrentValues(crParameter2);
            }

            strProgress = "Report Setup:";
            //create the report as a pdf file
            //create a unique filename based on the system date and time
            System.DateTime dt = System.DateTime.Now;
            strFilename = "Temp" + dt.ToString("yyyyMMddhhmmss") + ".pdf";

            strFilepath = "/OrielGold/pdfs/";
            dfdoCRExport = new DiskFileDestinationOptions();
            dfdoCRExport.DiskFileName = Server.MapPath(strFilepath + strFilename);
            eoReport = new ExportOptions();
            eoReport = rdReport.ExportOptions;
            eoReport.DestinationOptions = dfdoCRExport;
            eoReport.ExportDestinationType = ExportDestinationType.DiskFile;
            eoReport.ExportFormatType = ExportFormatType.PortableDocFormat;
            eoReport.ExportFormatOptions = new PdfRtfWordFormatOptions();

            strProgress = "Report Generation:";
            //export the report and send user to the pdf viewer screen
            rdReport.Export();
            rdReport.Close();
            if (intStatus == 2)
            {
                strSQL = "Update Reports set Generated=Yes where Report_ID = " + intReportID.ToString();
                helper.ExecuteNonQuery("Goldmine", strSQL);
            }
            Response.Redirect("ReportViewer.aspx?Report=" + strFilename);

        }
        catch (Exception ex)
        {
            (Master.FindControl("lblErrorMessage") as Label).Text = strProgress + " :" + ex.Message;
        }
        finally
        {
            if (rdrReports != null)
            {
                rdrReports.Dispose();
            }
            if (rdReport != null)
            {
                rdReport.Close();
            }
            helper.Close();
        }
    }

    private static void AssignTableConnections(CrystalDecisions.CrystalRep orts.Engine.Table table, ConnectionInfo connection)
    {
        try
        {
            //cache the logon info block
            TableLogOnInfo logOnInfo = table.LogOnInfo;

            //set the connection
            logOnInfo.ConnectionInfo = connection;
            //apply the connection
            table.ApplyLogOnInfo(logOnInfo);
        }
        catch (Exception ex)
        {
            throw new ArgumentException("Assign Table Connections: " + ex.Message);
        }
    }
}
Web.Config extract

<configuration>
        <appSettings>

      <add key ="AccessDB" value="d:\dev\goldmine\orielgold\Goldmine.mdb"/>

      <add key ="SourceFolder" value="d:\dev\goldmine\" />
      <add key ="DestinationFolder" value="d:\GMBackup\"/>

      <add key="ReportsFolder" value="d:\dev\goldmine\latest reports\"/>
      <add key="ZipFolder" value="d:\dev\goldmine\latest reports\Archive\"/>
        </appSettings>
    <connectionStrings>

    <add name="OrielAdmin" connectionString="Data Source=(local);Initial Catalog=OrielAdmin;Integrated Security=False;User=OrielUser;Password=mrpieman" providerName="System.Data.SqlClient"/>

    <add name="Orion" connectionString="Data Source=(local);Initial Catalog=PhaseIV;Integrated Security=False;User=OrielUser;Password=mrpieman" providerName="System.Data.SqlClient"/>


    <add name="Goldmine" connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=d:\dev\Goldmine\OrielGold\goldmine.mdb"/>

    <add name="GM" connectionString="Data Source=d:\dev\goldmine\common;Extended Properties=dBase IV;provider=Microsoft.Jet.OLEDB.4.0"/>
    <add name="GMBase" connectionString="Data Source=d:\dev\Goldmine\GMBase;Extended Properties=dBase IV;provider=Microsoft.Jet.OLEDB.4.0"/>
    </connectionStrings>

To make sure the database location routine was working I moved all the database files to a different location, modified the web.config file and then tried to generate the report and it did so without any problem.

has anybody any idea on what the error means?

Thanks
Robert





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connector redirectPort StuartAllen Apache Tomcat 0 September 3rd, 2007 10:17 PM
jk connector URGENT ISSUE supreet Apache Tomcat 1 March 31st, 2007 11:56 AM
Apache + JK Connector + Tomcat problem ! wireblock Apache Tomcat 6 March 23rd, 2005 06:17 AM
Ximian connector for Microsoft Exchange server skarmoo Linux 1 February 17th, 2004 07:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.