Best Approach from my exprerience,
Create a new aspx page, modified everythings inside Page_init() (because not working other stage), make sure also put CrystalReportViewer on markup views.
protected void Page_Init(object sender, EventArgs e)
{
rptfile = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
rptfile.Load(Server.MapPath("~/Reports/Report.rpt"));
rptfile.SetDatabaseLogon("sa", "123", @"192.168.102.1\Database", "Data");
rptfile.Refresh();
.....
OleDbDataAdapter sql = new OleDbDataAdapter(query, Connection);
DataSet ds = new DataSet();
sql.Fill(ds);
rptfile.SetDataSource(ds.Tables[0]);
this.CrystalReportViewer1.ReportSource = rptfile;
CrystalDecisions.Shared.ConnectionInfo connectinfo = new
CrystalDecisions.Shared.ConnectionInfo();
connectinfo.ServerName = @"192.168.102.1/Database";
connectinfo.UserID = "sa";
connectinfo.Password = "123";
connectinfo.DatabaseName = "Data";
CrystalDecisions.Shared.TableLogOnInfos TableLoginInfos =
this.CrystalReportViewer1.LogOnInfo;
foreach (CrystalDecisions.Shared.TableLogOnInfo TableLogon in
TableLoginInfos)
{
TableLogon.ConnectionInfo = connectinfo;
}
rptfile.SetParameterValue(@"param1", Class1.param1);
rptfile.SetParameterValue(@"param2", Class2.param2);
this.CrystalReportViewer1.HasToggleGroupTreeButton = false;
this.CrystalReportViewer1.HasToggleParameterPanelButton = false;
this.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
}
Inside your web.config (to help web server find the path in easy),
<configuration>
<configSections>
<sectionGroup name="businessObjects">
<sectionGroup name="crystalReports">
<section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null" />
<section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<businessObjects>
<crystalReports>
<rptBuildProvider>
<add embedRptInResource="true" />
</rptBuildProvider>
<crystalReportViewer>
<add key="ResourceUri" value="/crystalreportviewers13" />
</crystalReportViewer>
</crystalReports>
</businessObjects>
</configuration>