我在调用c#时收到“无效的映射类型值”这个错误

时间:2012-04-30 15:18:55

标签: c# sql-server crystal-reports

我创建了显示我的报告的方法然后我在运行时给了connectioninfo 但是当我连接到远程服务器时出现错误

 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;
    }
}

当删除oRepDoc.VerifyDatabase()时; 我得到错误无效的映射 顺便说一句,connectioninfo在sql server上工作

2 个答案:

答案 0 :(得分:0)

确保您的UserId和密码在MainClass中正确,数据库不期望加密密码或您传递加密值,并且用户有权访问该数据库。

答案 1 :(得分:0)

来自MSDN上的这个帖子的Tim Vasil说他通过在连接的服务器机器上安装Microsoft SQL Server Native Client来解决这个错误。

http://social.msdn.microsoft.com/forums/en-US/vscrystalreports/thread/3c8db743-f1fb-4021-bf46-f6aee8889932

以下是有关如何安装Microsoft SQL Server Native Client的一些链接:

http://msdn.microsoft.com/en-us/library/ms131321.aspx

http://msdn.microsoft.com/en-us/sqlserver/ff658532