Here is my code:
Expand|Select|Wrap|Line Numbers
- // InfoStoreConnectionHelper is a custom class to handle connection with Infostore
- // the report id is passed from another page
- ReportApplicationServer.InfoStoreConnectionHelper helper = new ReportApplicationServer.InfoStoreConnectionHelper();
- using (helper)
- {
- //get client document by reportId
- CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument doc = helper.GetClientDocumentByID(id);
- if (doc != null)
- {
- CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag props = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBagClass();
- CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos info = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos();
- CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo ci = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfoClass();
- props.Add("Data Source", ConfigurationManager.AppSettings["report_servername"]);
- props.Add("Initial Catalog", ConfigurationManager.AppSettings["report_dbname"]);
- ci.Attributes = props;
- ci.UserName = ConfigurationManager.AppSettings["report_username"];
- ci.Password = ConfigurationManager.AppSettings["report_password"];
- info.Add(ci);
- CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag pb = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBagClass();
- CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag lpb = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBagClass();
- lpb.Add("Data Source", ConfigurationManager.AppSettings["report_servername"]);
- lpb.Add("Initial Catalog", ConfigurationManager.AppSettings["report_dbname"]);
- lpb.Add("Provider", "SQLOLEDB");
- pb.Add("Database DLL", "crdb_ado.dll");
- pb.Add("QE_DatabaseType", "OLE DB (ADO)");
- pb.Add("QE_LogonProperties", lpb);
- pb.Add("QE_SQLDB", "true");
- CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo nci = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfoClass();
- nci.UserName = ConfigurationManager.AppSettings["report_username"];
- nci.Password = ConfigurationManager.AppSettings["report_password"];
- nci.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
- nci.Attributes = pb;
- foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table tbl in doc.Database.Tables)
- {
- tbl.ConnectionInfo = nci;
- }
- crViewer.ReportSource = doc;
- }
- }