数据库登录提示与CrystalReports.我正在使用此代码:privatevoidfrmReporte_Load(objectsender,System.EventArgse){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();}publicvoidimprimirReporte(){ReportDocumentrpt=newReportDocument();rpt.Load(mvarRutaReporte);rpt.SetDataSource(clsReportes.dsReporte);rpt.PrintToPrinter(1,false,1,1);}privateReportDocumentprepareReport(){节crSections;ReportDocumentcrReportDocument,crSubreportDocument;子报表对象crSubreportObject;报告对象crReportObjects;连接信息crConnectionInfo;数据库crDatabase;表格crTables;表登录信息crTableLogOnInfo;crReportDocument=newReportDocument();crReportDocument.Load(RutaReporte);CrReportDocument.SetDataSource(clsReportes.dsReporte.Tables[0]);crDatabase=crReportDocument.Database;crTables=crDatabase.Tables;crConnectionInfo=newConnectionInfo();crConnectionInfo.ServerName=ServerName;crConnectionInfo.DatabaseName=DBName;crConnectionInfo.UserID=DBUser;crConnectionInfo.Password=密码;foreach(CrystalDecisions.CrystalReports.Engine.TableaTableincrTables){crTableLogOnInfo=aTable.LogOnInfo;crTableLogOnInfo.ConnectionInfo=crConnectionInfo;aTable.ApplyLogOnInfo(crTableLogOnInfo);}//对于有子报表的报表//我放置报表当前部分的部分对象crSections=crReportDocument.ReportDefinition.Sections;//搜索报表对象的所有部分foreach(SectioncrSectionincrSections){crReportObjects=crSection.ReportObjects;//在所有报表中搜索子报表foreach(ReportObjectcrReportObjectincrReportObjects){if(crReportObject.Kind==ReportObjectKind.SubreportObject){crSubreportObject=(SubreportObject)crReportObject;//abroelsubreporteymelogeoconlosdatosdelreportegeneralcrSubreportDocument=crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);crDatabase=crSubreportDocument.Database;crTables=crDatabase.Tables;foreach(CrystalDecisions.CrystalReports.Engine.TableaTableincrTables){crTableLogOnInfo=aTable.LogOnInfo;crTableLogOnInfo.ConnectionInfo=crConnectionInfo;aTable.ApplyLogOnInfo(crTableLogOnInfo);我有一个类似的问题,现在已经解决了,所以我添加了这个回复,以防它可以帮助其他人在我的情况下为报告设置SQLServer登录时,请确保包含服务名称。因此,例如,确保您为Crystal提供“myservermyservice”而不仅仅是“myserver”。我的程序只能使用“myserver”从SQLServer访问数据,但Crystal需要提供“myservermyservice”。在Crystal中,您可以指定在每个报告级别的Crystal管理控制台(CMC)中生成报告时是否提示数据库登录。登录CMC,打开Reports>Processes>Database。在页面底部,您可以指定“提示用户进行数据库登录”、“使用SSO上下文进行数据库登录”或“使用与运行报表时相同的数据库登录”。选择第三个选项以使用存储在服务器上的凭据。你只要写report.SetDatabaseLogon("username","pwd",@"server","database");提供登录信息,那么运行代码时就不会出现数据库登录框。以上就是C#学习教程的全部内容:水晶报表数据库登录提示。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: