Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i created method to show my report then i give connectioninfo at runtime but when i connect to remote server i got error
 public bool ShowReport()
{
    try
    {
        //CrystalDecisions.CrystalReports.Engine.ReportDocument oRepDoc;
        //CrystalDecisions.Shared.TableLogOnInfo oLogInfo;
        //CrystalDecisions.CrystalReports.Engine.Table oTable;
        //CrystalDecisions.CrystalReports.Engine.FieldDefinition oField;
        //CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition oParamFieldDef;
        //CrystalDecisions.Shared.ParameterValues oParamValues;
        //CrystalDecisions.Shared.ParameterDiscreteValue oDiscretParamValue;
        //ParameterFields oParamList;
        //ParameterField oParamItem;

        if (!System.IO.File.Exists(ReportPath))
        {
            MessageBox.Show("ملف التقرير غير موجود فى المسار الصحيح", MainClass.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return false;
        }
        else
        {
            oRepDoc = new ReportDocument();
            oLogInfo = new TableLogOnInfo();
            Tables t;
            oRepDoc.Load(ReportPath, OpenReportMethod.OpenReportByTempCopy);
            //***********************************************************************************

            ConnectionInfo connection = new ConnectionInfo();
            if (MainClass.IntegratedSecurity) connection.IntegratedSecurity = true;
            else
            {

                connection.IntegratedSecurity = false;
                connection.UserID = MainClass.UserId;
                connection.Password = MainClass.Password;
            }
            connection.ServerName = MainClass.ServerName;
            connection.DatabaseName = MainClass.DatabaseName;
             t= oRepDoc.Database.Tables;
             foreach (CrystalDecisions.CrystalReports.Engine.Table oTab in t)
            {
                oLogInfo = oTab.LogOnInfo;
                oLogInfo.ConnectionInfo = connection;

                oTab.ApplyLogOnInfo(oLogInfo);

                //oLogInfo = null;
            }

            //***********************************************************************************

            oRepDoc.Refresh();
            oRepDoc.VerifyDatabase(); // Very Important Line
            //***********************************************************************************
            // First Way To Pass Report Parameters Value
            foreach (Range oRange in oRangeList)
            {
                oRepDoc.SetParameterValue(oRange.RangeName, oRange.RangeValue);
            }
            oRangeList.Clear();
            //***********************************************************************************
            // Second Way To Pass Report Parameters Value
            //ParameterValues oCurrentParameterValues;
            //ParameterDiscreteValue oParameterDiscreteValue;
            //CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions oParameterFieldDefinitions = oRepDoc.DataDefinition.ParameterFields;
            //foreach (Range oRange in oRangeList)
            //{
            //    oCurrentParameterValues = new ParameterValues();
            //    oParameterDiscreteValue = new ParameterDiscreteValue();
            //    oParameterDiscreteValue.Value = oRange.RangeValue;
            //    oCurrentParameterValues.Add(oParameterDiscreteValue);
            //    ParameterFieldDefinition oParameterFieldDefinition = oParameterFieldDefinitions[oRange.RangeName];
            //    oParameterFieldDefinition.ApplyCurrentValues(oCurrentParameterValues);
            //}
            //oRangeList.Clear();
            //***********************************************************************************
            // Pass "Company Name" And "Telephone" And "Printed By"  To Report
            FormulaFieldDefinition oFormulaFieldDefinition;
            FormulaFieldDefinitions oFormulaFieldDefinitions = oRepDoc.DataDefinition.FormulaFields;

            oFormulaFieldDefinition = oFormulaFieldDefinitions["For_CompanyName"];
            oFormulaFieldDefinition.Text = string.Format("\"{0}\"", MainClass.CompanyName);
            oFormulaFieldDefinition = oFormulaFieldDefinitions["For_CompanyTel"];
            oFormulaFieldDefinition.Text = string.Format("\"{0}\"", MainClass.CompanyTel);
            oFormulaFieldDefinition = oFormulaFieldDefinitions["For_PrintedBy"];
            oFormulaFieldDefinition.Text = string.Format("\"{0}\"", MainClass.GetUserName(MainClass.SystemUserId));
            //***********************************************************************************
        }
        if (Destination == ReportDestination.Printer)
        {
            oRepDoc.PrintOptions.PrinterName = PrinterName;
            oRepDoc.PrintToPrinter(NumberofCopies, Collate, StartPage, EndPage);
            return true;
        }
        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, MainClass.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return false;
    }
}

when depugging oRepDoc.VerifyDatabase();
i got error invalid mapping by the way connectioninfo works on sql server
Posted
Updated 30-Apr-12 5:22am
v2
Comments
nagiub2007 2-May-12 4:04am    
e i debugged my code in statement oRepDoc.VerifyDatabase(); error raised and alredy i connected to remote database with same userid and password i need help please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900