I am facing problem with crystal reprot when i run that report on to the other machine and the database source is not the same as the machine where the reprots where created. It gives a logon Failed Message.
I tried the following code as well but still it give the same problem.
Can anybody help me.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
 
namespace CrystalReport_Change_connection
{
    public partial class Form1 : Form
    {
        CrystalReport1 rpt = new CrystalReport1();        
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            string path1 = Application.StartupPath+"test.mdb";
     
        try
        {
         
            rpt.DataSourceConnections[0].SetConnection(path1, path1, false);
            crystalReportViewer1.ReportSource = rpt; 
        }
        catch(CrystalDecisions.ReportSource.EnterpriseLogonException  exp)
        {
            MessageBox.Show(exp.Message);
        }
       
        }
    }
}

Sorry line 28 in my code should be

rpt.DataSourceConnections[0].SetConnection(path1, "", false); [\code][code=csharp]
rpt.DataSourceConnections[0].SetConnection(path1, "", false);
[\code]

Some things to check:
1) using subreports pointing to datasource with invalid path
2) are you saving data with report? this used to cause a variety of problems and although it might not be the exact cause, you might get different results if you change this option
3) are the schemas exactly the same for each of the datasource locations?

The problem i encountered was when i made my Crystal report using the wizard i have to select a database when i am making the ADO connection.
Say i selected database in "D:\MyProject\DatabaseName.mdb".
After that when i Copy my execution file(.exe file) and my database to another machine.
If i copy those 2 files to another location. say somewhere in C: drive
it does not work.
I always had to maintain a copy of my database at D:\MyProject Folder.
What i want is to dynamically change my database path to the Application.StartupPath.

Did you check to see if the report design (.rpt file) is using the option to "save data with report?" The reason I ask is because when this option is used it might be also maintaining the original path to the DB connection; and even though you are supplying an alternate path in your connection string, the report might be trying to validate the path to the data stored with the report. Does this make sense?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.