Crystal reports CrystalReportsViewer会提示输入密码,但不会';我不能接受

Crystal reports CrystalReportsViewer会提示输入密码,但不会';我不能接受,crystal-reports,Crystal Reports,我正在尝试使用CrystalReportViewer控件在Visual Studio 2012项目中显示报告。我提供连接数据库所需的所有信息,包括服务器名称、端口号、数据库名称、用户名和密码。当我运行下面的程序时,该控件向我显示一个对话框,其中包括正确的连接字符串、数据库名称和用户,并提示我输入密码,尽管我已经给了密码。当我给它正确的密码时,一个弹出窗口显示“登录失败,再试一次”。我做错了什么 顺便说一下,此报表中没有子报表。当我运行下面的程序时,我在处理子报表的代码中放置了一个断点,但它从未被

我正在尝试使用CrystalReportViewer控件在Visual Studio 2012项目中显示报告。我提供连接数据库所需的所有信息,包括服务器名称、端口号、数据库名称、用户名和密码。当我运行下面的程序时,该控件向我显示一个对话框,其中包括正确的连接字符串、数据库名称和用户,并提示我输入密码,尽管我已经给了密码。当我给它正确的密码时,一个弹出窗口显示“登录失败,再试一次”。我做错了什么

顺便说一下,此报表中没有子报表。当我运行下面的程序时,我在处理子报表的代码中放置了一个断点,但它从未被命中

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;

namespace Example
{
    public partial class Form1 : Form
    {
        private string _serverName;
        private string _databaseName;
        private string _user;
        private string _passwd;
        private ReportDocument _report;

        public Form1()
        {
            InitializeComponent();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            string reportFile = "C:\\Users\\rdrichardson\\OneDrive - Rad-Con\\CAPS Builds\\trunk\\Debug Crawfordsville\\Reports\\English\\allbases_no_subreports.rpt";
            _report = new ReportDocument();            
            _report.Load(reportFile);

            _serverName = "Provider=Provider=PostgreSQL OLE DB Provider;Data Source=localhost;Port=5432timeout=1000;";
            // _serverName = "Driver={PostgreSQL};Server=IP address;Port=5432;Database=Algoma;Uid=caps;Pwd=asdlkjqp;";
            // _serverName = "Driver={PostgreSQL};Server=IP address;Port=5432;";
            _databaseName = "Algoma";
            _user = "caps";
            _passwd = "asdlkjqp";

            LogOnToTables();

            crystalReportViewer1.ReportSource = _report;
        }
        private void LogOnToTables()
        {
            string location;
            ReportObjects crReportObjects;
            SubreportObject crSubreportObject;
            ReportDocument crSubreportDocument;
            Database crDatabase;
            Tables crTables;
            TableLogOnInfo crTableLogOnInfo;

            ConnectionInfo crConnectInfo = new ConnectionInfo();

            if (_report == null) return;


            // Setup the ODBC/ADO connect string
            crConnectInfo.DatabaseName = _databaseName;
            crConnectInfo.ServerName = _serverName;
            crConnectInfo.Type = ConnectionInfoType.CRQE;
            crConnectInfo.UserID = _user;
            crConnectInfo.Password = _passwd;

            _report.SetDatabaseLogon(_user, _passwd);
            _report.DataSourceConnections.Clear();

            crDatabase = _report.Database;
            crTables = crDatabase.Tables;

            //loop through all the tables and pass in the connection info
            foreach (Table crTable in crTables)
            {
                location = crTable.Location;
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectInfo;
                // crTable.LogOnInfo.ConnectionInfo.DatabaseName = string.Empty;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }

            //set the crSections object to the current report's sections
            Sections crSections = _report.ReportDefinition.Sections;

            //loop through all the sections to find all the report objects
            foreach (Section crSection in crSections)
            {
                crReportObjects = crSection.ReportObjects;
                //loop through all the report objects to find all the subreports
                foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject in crReportObjects)
                {
                    if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        //you will need to typecast the reportobject to a subreport 
                        //object once you find it
                        crSubreportObject = (SubreportObject)crReportObject;

                        //open the subreport object
                        crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

                        //set the database and tables objects to work with the subreport
                        crDatabase = crSubreportDocument.Database;
                        crTables = crDatabase.Tables;

                        //loop through all the tables in the subreport and 
                        //set up the connection info and apply it to the tables
                        foreach (Table crTable in crTables)
                        {
                            location = crTable.Location;
                            crTableLogOnInfo = crTable.LogOnInfo;
                            crTableLogOnInfo.ConnectionInfo = crConnectInfo;
                            crTable.ApplyLogOnInfo(crTableLogOnInfo);
                        }
                    }
                }
            }
        }
    }


}
此值是硬编码的,无论您输入什么,它都将使用此密码。尝试提供实际用户/密码,而不是
asdlkjqp


此值是硬编码的,无论您输入什么,它都将使用此密码。尝试提供实际用户/密码,而不是
asdlkjqp

您是否在新的/简单的/空的报告中尝试了此代码?它是一个简单的报告。它没有子报表(通过在处理子报表的代码中放置断点并查看它是否被命中来验证)。我建议尝试使用新报表。也许你的报告“坏了”。如果一个新的报告有效,那么它必须是其他的。你有没有在一个新的/简单的/空的报告中尝试过这段代码?它是一个简单的报告。它没有子报表(通过在处理子报表的代码中放置断点并查看它是否被命中来验证)。我建议尝试使用新报表。也许你的报告“坏了”。如果一份新的报告有效,那么它必须是其他的。谢谢你,但是你误解了这个问题。“caps”和“asdlkjqp”是有效的用户名和密码。Crystal Reports不应该向我询问其他密码。即使是这样,我重新输入“asklkjqp”,它也应该接受它,而不是说“登录失败”。谢谢,但是你误解了这个问题。“caps”和“asdlkjqp”是有效的用户名和密码。Crystal Reports不应该向我询问其他密码。即使是这样,我重新输入“asklkjqp”,它也应该接受它,而不是说“登录失败”。
_user = "caps";
_passwd = "asdlkjqp";