Search code examples
c#crystal-reportsvisual-studio-2019

Exception thrown: 'CrystalDecisions.CrystalReports.Engine.DataSourceException'


I'm developing an application in visual studio using c# and Crystal report. I'm getting some problem to connect db access to my app. I found out some example about that , but no work for me. Just I need to connect a db and print it on viewer, but I found example with oledbConnect + OleDbDataAdapter. I have to pass only string connection to 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);
            }
        }

     
    }

load access informazion

ODBC Driver

The report connection into Visual Studio work fine. Can anyone give me some info to solve this problem?


Solution

  • One suspect is a 32-bit vs 64-bit mismatch. For example, if VS is 32-bit but you are deploying as a 64-bit app.

    A 64-bit app must use a 64-bit ODBC DSN or a 64-bit database connectivity driver.