Problem description:
Recently, it involves crystal report development. The original system already has some Crystal Reports, which are placed in Server A. These Crystal Reports need to extract data from Server B. A new website is created on Server C, you need to display the Crystal Report in Server A on the Web page of the website. Structure:
Development Environment: VS2008, Crystal Report 2008, and Windows2003 domain environment
Solution:
1. Analyze the ODBC settings required for extracting the crystal report data in Server A, because the Crystal Report in Server A extracts data from Server B, therefore, in Server A, you need to create an ODBC Data Source pointing to the database in Server B. This task was completed when you created the crystal report. Here, we need to analyze its data source, it serves as a reference when we create an ODBC data source in Server C (the two settings are consistent ).
First, view the data source used by the Server A crystal report.
Go to Server a odbc settings to analyze the data source settings
2. Create A virtual directory in IIS on Server C. This directory directly references the folder location of the crystal report in Server.
3. Set the ODBC data source in Server C. The settings here should be the same as the ODBC settings used in the crystal report in Server. Point to the database data source in Server C.
4. implement, publish, and run ASP. NET code. The Code is as follows:
View Code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> protected void btnSD1CTX_Click (object sender, EventArgs e) {string repFilePathRemoteParamsCtx2 = System. web. httpContext. current. server. mapPath (".. /Crystal REPORT Test. rpt "); DateTime dtime = new DateTime (); // here, dtime is the parameter to be passed in by Test in the crystal report try {dtime = Convert. toDateTime (txtBxParam. text. toString (). trim ();} catch (Exception ex) {string ke = ex. toString ();} this. crystalReportSource1.ReportDocument. load (repFilePathRemoteParamsCtx2); // Note: NexusSQL is the ODBC connection name set in the preceding ODBC settings. this. crystalReportSource1.ReportDocument. setDatabaseLogon ("UserID", "PassWord", "NexusSQL", "Database Name"); this. crystalReportSource1.ReportDocument. setParameterValue ("DateRaised", dtime); // input the parameter this. crystalReportSource1.DataBind (); this. crystalReportViewer1.ReportSource = this. crystalReportSource1; CrystalReportViewer1.AutoDataBind = false; this. crystalReportViewer1.DataBind (); CrystalReportViewer1.BestFitPage = true ;}
Reprinted: http://www.cnblogs.com/wsdj-ITtech/archive/2010/05/28/1746151.html