快逸报表动态改变数据库连接的问题
客户的数据库的用户名和密码会随着业务的增加而增加,也就是连接数据库的url是不确定的,所以不能配置在web.config文件,我们可以在发布报表时动态改变数据库的url。
需求实现
第一步,写一个计算报表defineBean的CS类:
using System;
using System.IO;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Web.Hosting;
using com.runqian.report.usermodel;
using com.runqian.report.graph;
using com.runqian.report.cellset;
using System.Data.OleDb;
public partial class reportMES_frmGraphShow : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//取得报表名,报表根目录
string reportName = “”;
String reportFileHome = com.runqian.report.usermodel.Context.ReportConfig.ReportFileHome;
string beanName = “aa”;
//获取报表定义
ReportDefine rd = new ReportDefine(“D://Program Files (x86)//bonzer//webroot//reportFiles//sql2000.raq”);
//把rd放入HttpContext中
String str=”provider=sqloledb;server=192.168.0.53;uid=sa;pwd=sa;database=testcopy”;
OleDbConnection conn=new OleDbConnection(str);
conn.Open();
Env env = new Env(rd);
env.setConnection(conn);
Engine eg = new Engine(env);
Report report = eg.calc();
Context.Items[beanName] = report;
//设置参数及其他公共操作
HtmlTag_1.BeanName = beanName;
}
}
第二步,我们设计一个aspx用define的方式发布报表:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”api.aspx.cs” Inherits=”reportMES_frmGraphShow” %>
<%@ Register Assembly=”report35net” Namespace=”com.runqian.report.tag” TagPrefix=”rq” %>
<html>
<head id=”Head1″ runat=”server”>
<title runat=”server” id=”tlt”>图表</title>
</head>
<body leftmargin=”0″ topmargin=”0″ rightmargin=”0″ bottomMargin=”0″>
<table cellspacing=”0″ cellpadding=”0″ border=”0″>
<tr><td>
<rq:HtmlTag
ID=”HtmlTag_1″
Name=”report1″
SrcType=”defineBean”
runat=”server”
needScroll=”yes”
FuncBarLocation = “top”
needPrint=”yes”
NeedSaveAsExcel=”yes”
NeedSaveAsPdf=”yes”
/>
</td></tr>
</table>
</body>
</html>