Thanks Karthik www.f5Debug.net
protected void Page_Load(object sender, EventArgs e) { // this.CrystalReportSource1.ReportDocument.Load(@"C:\Report.rpt"); ReportDocument doc = new ReportDocument(); doc.Load(@"C:\Report.rpt"); //2) Once I have the data I need to apply it to the connection of the report ConnectionInfo crConnection = new ConnectionInfo(); crConnection.UserID = "username"; crConnection.ServerName = "serverName"; crConnection.DatabaseName = ""; crConnection.Password = "password"; AssignConnectionInfo(doc, crConnection); doc.SetDatabaseLogon(crConnection.UserID, crConnection.Password, crConnection.ServerName, crConnection.DatabaseName); CrystalReportViewer1.ReportSource = doc; CrystalReportViewer1.RefreshReport(); } private void AssignConnectionInfo(ReportDocument document, ConnectionInfo crConnection) { foreach (CrystalDecisions.CrystalReports.Engine.Table table in document.Database.Tables) { TableLogOnInfo logOnInfo = table.LogOnInfo; if (logOnInfo != null) { table.ApplyLogOnInfo(table.LogOnInfo); table.LogOnInfo.TableName = table.Name; table.LogOnInfo.ConnectionInfo.UserID = crConnection.UserID; table.LogOnInfo.ConnectionInfo.Password = crConnection.Password; table.LogOnInfo.ConnectionInfo.DatabaseName = crConnection.DatabaseName; table.LogOnInfo.ConnectionInfo.ServerName = crConnection.ServerName; } } }
Login to post response