Changing crystal report connection at runtime
-
hey guyz.. anyone know how to change crystal report connection at runtime, im just a beginner of using this.. i can generate reports and filter records, but im worrying about the connection if ever i run this to other computer...i need your help badly...tnx guyz in advance
-
hey guyz.. anyone know how to change crystal report connection at runtime, im just a beginner of using this.. i can generate reports and filter records, but im worrying about the connection if ever i run this to other computer...i need your help badly...tnx guyz in advance
-
hey guyz.. anyone know how to change crystal report connection at runtime, im just a beginner of using this.. i can generate reports and filter records, but im worrying about the connection if ever i run this to other computer...i need your help badly...tnx guyz in advance
Try this:
Tables tables = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = connectionInfo; table.ApplyLogOnInfo(tableLogonInfo); }
reportDocument is your instance of the CrystalDecisions.CrystalReports.EngineReportDocument class, and connectionInfo is the instance of the ConnectionInfo class where you configure the database, username, and password. You can then manage the connection through the web.config (for web) or app.config (for pc based) file, thus allowing you to change it w/out having to recompile. Or you could check certain circumstances, and depending on the outcome, point to different sources. -
Try this:
Tables tables = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = connectionInfo; table.ApplyLogOnInfo(tableLogonInfo); }
reportDocument is your instance of the CrystalDecisions.CrystalReports.EngineReportDocument class, and connectionInfo is the instance of the ConnectionInfo class where you configure the database, username, and password. You can then manage the connection through the web.config (for web) or app.config (for pc based) file, thus allowing you to change it w/out having to recompile. Or you could check certain circumstances, and depending on the outcome, point to different sources.