Crystal Report数据库登录参数

时间:2015-05-25 03:42:45

标签: c# database-connection crystal-reports-xi

我有一个基于Windows的c#应用程序使用Crystal报表作为我的报告工具。我已经提供了所有登录和数据库信息,但是当我运行并部署它时,它仍然要求进行数据库登录。

这是我的代码。

ReportDocument rpt = new ReportDocument();


        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;

        rpt.Load("C:/Operation/Reports/po.rpt");

        crConnectionInfo.ServerName = "192.4.4.4";
        crConnectionInfo.DatabaseName = "Operations";
        crConnectionInfo.UserID = "sa";
        crConnectionInfo.Password = "xxxxxx";




        ParameterFieldDefinitions crParameterFieldDefinitions;
        ParameterFieldDefinition crParameterFieldDefinition;
        ParameterValues crParameterValues = new ParameterValues();
        ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

        crParameterDiscreteValue.Value = DbClass.PONumber;
        crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
        crParameterFieldDefinition = crParameterFieldDefinitions["ParameterPO"];
        crParameterValues = crParameterFieldDefinition.CurrentValues;

        crParameterValues.Clear();
        crParameterValues.Add(crParameterDiscreteValue);
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);



        CrTables = rpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }

        crpt.Refresh();
        crpt.ReportSource = rpt;

我的头痛是问题所在...如果有人知道这件事,请给我一个想法..

谢谢!

1 个答案:

答案 0 :(得分:0)

首先打开您的连接。使用这个:

SqlConnection myConnection = new SqlConnection("xxx");
 myConnection.Open();
 // Your Code
 myConnection.Close();

然后关闭连接。