带水晶报告的数据库登录提示

我正在尝试显示一些报告 ,其中包含一些 报告 ,但每次显示报告时都会抛出一些要求数据库连接的对话框。 我正在使用此代码:

private void frmReporte_Load(object sender, System.EventArgs e) { Clave = ConfigurationSettings.AppSettings["Password"].ToString(); NombreBD = ConfigurationSettings.AppSettings["CatalogBD"].ToString(); NombreServidor = ConfigurationSettings.AppSettings["Servidor"].ToString(); ; UsuarioBD = ConfigurationSettings.AppSettings["UserID"].ToString(); this.crtReportes.ReportSource = this.prepareReport(); } public void imprimirReporte() { ReportDocument rpt = new ReportDocument(); rpt.Load(mvarRutaReporte); rpt.SetDataSource(clsReportes.dsReporte); rpt.PrintToPrinter(1, false, 1, 1); } private ReportDocument prepareReport() { 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.Tables[0]); 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); } } } } return crReportDocument; } 

我有一个类似的问题,它现在已经解决了,所以我添加这个回复,以防它可能在我的情况下帮助其他人。

为报告设置SQL Server登录信息时,请确保包含服务名称。 因此,例如,确保你给的是Crystal“myserver \ myservice”而不仅仅是“myserver”。

我的程序只能使用“myserver”从SQL Server访问数据,但Crystal需要给出“myserver \ myservice”。

在Crystal中,您可以指定是否在Crystal Management Console(CMC)@每个报告级别提示db login @生成报告的时间。 登录CMC,打开报告>进程>数据库。 在页面底部,您可以指定“提示用户进行数据库登录”,“使用SSO上下文进行数据库登录”或“使用与运行报表时相同的数据库登录”。 选择第三个选项以使用存储在服务器中的凭据。

您只需编写report.SetDatabaseLogon(“username”,“pwd”,@“server”,“database”); 提供登录信息,然后在运行代码时不会出现数据库登录框。