抛出异常:'CrystalDecisions.CrystalReports.Engine.DataSourceException'

问题描述 投票:0回答:1

我正在使用 C# 和 Crystal Report 在 Visual Studio 中开发一个应用程序。我在将数据库访问连接到我的应用程序时遇到了一些问题。我找到了一些例子,但对我没有用。 只是我需要连接一个数据库并将其打印在查看器上,但我发现了 oledbConnect + OleDbDataAdapter 的示例。我必须只将字符串连接传递给 report.SetDataSource。

public partial class Form1 : Form
    {
        private string pathReport;
       
        private const string CONNECTION_STRING = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Xtreme.mdb";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"D:\",
                Title = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt = "txt",
                Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*",
                FilterIndex = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
                pathReport = openFileDialog1.FileName;
                  
            }
        }
 
       
        private void btnViewer_Click(object sender, EventArgs e)
        {
            try
            {
               
                OleDbConnection oleDbConnection = new OleDbConnection(CONNECTION_STRING);
             
                ReportDocument rd = new ReportDocument();
                 rd.Load(@pathReport);
                               
                rd.SetDataSource(oleDbConnection);
           
                crViewer.ReportSource = rd;
                crViewer.Refresh();
       
                

            }
            catch(Exception ex)
            {
                Console.WriteLine("Error click viewer " + ex.Message);
            }
        }

     
    }

加载访问信息

ODBC 驱动

与 Visual Studio 的报告连接工作正常。 谁能给我一些信息来解决这个问题?

c# crystal-reports visual-studio-2019
1个回答
0
投票

一个嫌疑人是 32 位与 64 位不匹配。 例如,如果 VS 是 32 位的,但您正在部署为 64 位应用程序。

64 位应用程序必须使用 64 位 ODBC DSN 或 64 位数据库连接驱动程序。

© www.soinside.com 2019 - 2024. All rights reserved.