Hi everyone, I created a crystal report viewer and I have it to load some report with subreports and a dataset filled with all the data the report needs.
My thing is everytime I try to display the report it prompts a dialog box asking for database authentication, which I don't need cause i'm passing an already filled Dataset.
My code is this:
TableLogOnInfo logOnInfo = new TableLogOnInfo(); int i = 0; ReportDocument rpt = new ReportDocument(); String SQL1 = ""; SQL1 = mvarRutaReporte;
try { logOnInfo.ConnectionInfo.ServerName = mvarNombreServidor; logOnInfo.ConnectionInfo.DatabaseName = mvarNombreBD; logOnInfo.ConnectionInfo.UserID = mvarUsuarioBD; logOnInfo.ConnectionInfo.Password = mvarClave; rpt.Load(SQL1); rpt.SetDataSource(clsReportes.dsReporte);
foreach (Table tabla in rpt.Database.Tables) { tabla.ApplyLogOnInfo(logOnInfo); if (tabla.TestConnectivity()) { MessageBox.Show("Error en la Coneccion de las tablas del reporte!!!", "S.I.M.M."); } } #endregion #region autenticando los subreportes foreach (ReportDocument Subreporte in rpt.Subreports) { Subreporte.Database.Tables[0].ApplyLogOnInfo(logOnInfo); if (Subreporte.Database.Tables[0].TestConnectivity()) { MessageBox.Show("Error en la Coneccion de las tablas del SubReporte!!!", "S.I.M.M."); } } this.crtReportes.ReportSource = rpt; } catch (Exception a) { MessageBox.Show(a.ToString()); }
I even tried to handle the authentication with this routine:
Sections crSections; ReportDocument crReportDocument, crSubreportDocument; SubreportObject crSubreportObject; ReportObjects crReportObjects; ConnectionInfo crConnectionInfo; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; crReportDocument = new ReportDocument(); crReportDocument.Load(RutaReporte); crReportDocument.SetDataSource(clsReportes.dsReporte); crDatabase = crReportDocument.Database; crTables = crDatabase.Tables; crConnectionInfo = new ConnectionInfo(); crConnectionInfo.ServerName = NombreServidor ; crConnectionInfo.DatabaseName = NombreBD; crConnectionInfo.UserID = UsuarioBD; crConnectionInfo.Password = Clave; foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); } // Para los reportes que poseen subreportes // pongo el objeto seccion del la seccion actual del reporte crSections = crReportDocument.ReportDefinition.Sections; // busco en todas las secciones el objeto reporte foreach (Section crSection in crSections) { crReportObjects = crSection.ReportObjects; //busco en todos los reportes por subreportes foreach (ReportObject crReportObject in crReportObjects) { if (crReportObject.Kind == ReportObjectKind.SubreportObject) { crSubreportObject = (SubreportObject)crReportObject; //abro el subreporte y me logeo con los datos del reporte general crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName); crDatabase = crSubreportDocument.Database; crTables = crDatabase.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); } } } }
Any help?
------------- lol
|