最近在做SSRS项目时,遇到这么一个情形:该项目有多个数据库,每个数据库都在不同的服务器,但每个数据库所拥有的数据库对象(table/view/SPs/functions)都是一模一样的,后来结合网络上众多的资源找到了解决方案,即Data Processing Extensio(DPE)。所谓DPE,直白地说就是开发自己的DLL去扩展SSRS的数据源,具体的操作如下所示:

1. 新建类库项目,并引入以下两个DLL:

C:\Program Files\Microsoft SQL Server\MSSQLSERVER\Reporting Services\ReportServer\bin\Microsoft.ReportingServices.Interfaces.dll

  C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll

2. 根据参数获取Connection String:新建DBConnection类文件,实现接口IDbConnectionExtension并且重写其中的方法:

  A. SetConfiguration():主要是实现读取数据库连接的配置文件:

public void SetConfiguration(string configuration)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(configuration);
string ConfigFilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + xmlDoc.ChildNodes[].Attributes["configSource"].InnerText;
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = ConfigFilePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
foreach (ConnectionStringSettings cf in config.ConnectionStrings.ConnectionStrings)
{
connectionStrings.Add(cf.Name, cf.ToString());
}
}

  B. GetConnectionByParameter():主要根据User的选择来返回相应的Database connection;

public SqlConnection GetConnectionByParameter(IDataParameterCollection parameters)
{
var connString = connectionStrings["CentralDBConnString"]; foreach (DBParameter param in parameters)
{
if (param.ParameterName.Equals("ClinicCode"))
{
//Using the first value if the ClinicCode were selected for more than 1 option.
if (param.Values != null && param.Values.Length > 1)
{
param.Value = param.Values[0];
}
connString = GetConnectionStringsConfig(param.Value.ToString());
}
} return new SqlConnection(connString);
}

3. 执行SQL命令:新建DBCommand类文件,实现接口IDbCommand并且重写其中的方法:

  A. ExecuteReader(): 执行SQL Command;

public IDataReader ExecuteReader(CommandBehavior behavior)
{
Debug.WriteLine("IDBCommand.ExecuteReader with CommandBehavior." + behavior); // get connection based on parameters
using (SqlConnection conn = m_connection.GetConnectionByParameter(this.Parameters))
{
conn.Open(); SqlCommand cmd = new SqlCommand(CommandText, conn);
cmd.CommandType = (System.Data.CommandType)this.CommandType;
foreach (DBParameter param in this.Parameters)
{
if (param.Value != null)
cmd.Parameters.Add(new SqlParameter(param.ParameterName, param.Value));
else
cmd.Parameters.Add(new SqlParameter(param.ParameterName, DBNull.Value));
} SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
System.Data.DataSet dsResult = new System.Data.DataSet();
sqlDA.Fill(dsResult);
m_dataTable = dsResult.Tables[]; conn.Close();
return new DBDataReader(this);
}
}

4. 小结:最后还需要实现的几个接口包括:IDataReader,IDataParameter, IDataMultiValueParameter,IDataParameterCollection,并要实现其中的某些方法。完成以上步骤后基本所有的工作已经完成,接下来就是部署DLL了。

5. 部署:部署有两个选择,一种是供SSRS在设计模式使用DPE,另一种是供SSRS在发布后在Reporting Server上使用DPE。两种方法的发布路径及配置文件均不同,但过程都极为相似。以下是两种方式的区别:

1. Open the project "ProjectName" and rebuild it ;
2. Copy the file "ProjectName.dll" and "ProjectName.pdb" inside folder "ProjectName\ProjectName\bin\Debug" to path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\";
3. Copy file "ProjectName.config" inside project root directory to path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\";
4. Open the file "RSReportDesigner.config" inside folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\"(The exactly path base on the Visio Studio version you installed in your local);
4.1. Find the node <Data> inside node <Extensions>, add node "<Extension Name="XXXX DataSource Extension" Type="ProjectName.DBConnection, ProjectName" />" inside node <Data>;
4.2 Find the node <Desinger> inside node <Extensions>, add node "<Extension Name="XXXX DataSource Extension" Type="Microsoft.ReportingServices.QueryDesigners.GenericQueryDesigner,Microsoft.ReportingServices.QueryDesigners"/>" inside node <Desinger>; 5. Open the file "RSPreviewPolicy.config" inside folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\"(The exactly path base on the Visio Studio version you installed in your local);
5.1 Find the node <Data> inside node <Extensions>, add node below content inside node <CodeGroup>;
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="XXXX DataSource Extension"
Description="Code group for my Custom DataSource for data processing extension">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\ProjectName.dll"
/>
</CodeGroup> 6. Open your DataSource of SSRS report ,select the Embedded connections and choice the DPE named "XXXX DataSource Extension" from the dropdownlist of Type;
7. Click OK button to use the DPE. PS.
1. Please close and open your Visio Studio again, if you can not find the DPE named "XXXX DataSource Extension" after you finished above steps; Using the DEP in Report Server(After deploy to Reporting Server):
***********************************************************************************************************
1. Open the project "ProjectName" and rebuild it ;
2. Copy the file "ProjectName.dll" and "ProjectName.pdb" inside folder "ProjectName\ProjectName\bin\Debug" to path "C:\Program Files\Microsoft SQL Server\MSRS12.MSSQLSERVER\Reporting Services\ReportServer\bin\";
3. Copy file "ProjectName.config" inside project root directory to path "C:\Program Files\Microsoft SQL Server\MSRS12.MSSQLSERVER\Reporting Services\ReportServer\bin\";
4. Open the file "rsreportserver.config" inside folder "C:\Program Files\Microsoft SQL Server\MSRS12.MSSQLSERVER\Reporting Services\ReportServer\"(The exactly path base on the Visio Studio version you installed in your local);
4.1. Find the node <Data> inside node <Extensions>, add below content inside node <Data>;
<Extension Name="DPEName" Type="ProjectName.DBConnection,ProjectName">
<Configuration>
<connectionStrings configSource="\bin\ProjectName.config" />
</Configuration>
</Extension>
4.2 Find the node <Desinger> inside node <Extensions>, add below inside node <Desinger>; 5. Open your DataSource of SSRS report in Reporting Server,then open the report through right click it and select "Manage";
6. Click "Data Source" from the menu located left side of the new page;
7. Select "A Custom Data Source" in the right side of the page,followed by selecting DPE named "XXXX DataSource Extension" as the Data source type;
8. Click Apply button to use the DPE. PS.
1. Please restart the Reporting Services if you still can not find the DataSource manage page after you finished above steps;

6. 总结:经过这次对DPE的使用,总体来说没有什么难度,但在使用的过程中最好能下载一个例子,然后在其基础上进行修改,这样会节约很多时间。此外还要注意的是使用的.Net Framework的版本,刚开始由于版本不正确,导致一直找不到自定义的DPE,最后经过自己重复测试才找到原因!以下是Google是找到的几个链接,在我使用的过程中帮了我很大的忙:

SQL Server Reporting Service(SSRS) 第五篇 自定义数据处理扩展DPE(Data Processing Extension)的更多相关文章

  1. SQL Server Reporting Services 自定义数据处理扩展DPE(Data Processing Extension)

    最近在做SSRS项目时,遇到这么一个情形:该项目有多个数据库,每个数据库都在不同的服务器,但每个数据库所拥有的数据库对象(table/view/SPs/functions)都是一模一样的,后来结合网络 ...

  2. SQL Server Reporting Service(SSRS) 第三篇 SSRS Matrix用法

    以前不是太清楚SSRS的功能,自从最近有了了解之后,发现它的功能的确很强大.对于Matrix,刚开始我竟不知道它到底有什么用,现将通过一个例子中去理解Matrix,以及和分组Group结合使用的便利性 ...

  3. SQL Server Reporting Service(SSRS) 第七篇 常见错误汇总

    1. The current action cannot be completed. The user data source credentials do not meet the requirem ...

  4. SQL Server Reporting Service(SSRS) 第六篇 SSRS 部署总结

    前段时间完成了第一批次SSRS报表的开发,本来以为大功已经告成,结果没有想到在整个发布与部署过程中还是遇到了很多的问题,现将这些问题一一列举出来,希望对以后能够有所启发! 1. 关于数据源与数据集的发 ...

  5. SQL Server Reporting Service(SSRS) 第四篇 SSRS 用法总结

    1. 如何让表头在每页显示(译) A. 打开高级模式:  在分组栏中点击Column Goups右侧的箭头选择高级模式; B. 找到第一个Static组 在Row Groups区域中(注意不是Colu ...

  6. SQL Server Reporting Service(SSRS) 第四篇 SSRS 常见问题总结

    1. 如何让表头在每页显示(译) A. 打开高级模式:  在分组栏中点击Column Goups右侧的箭头选择高级模式; B. 找到第一个Static组 在Row Groups区域中(注意不是Colu ...

  7. SQL Server Reporting Service(SSRS) 第二篇 SSRS数据分组Parent Group

    SQL Server Reporting Service(SSRS) 第一篇 我的第一个SSRS例子默认使用Table进行简单的数据显示,有时为了进行更加直观的数据显示,我们需要按照某个字段对列表进行 ...

  8. SQL Server Reporting Service(SSRS) 第一篇 我的第一个SSRS例子

    很早就知道SQL SERVER自带的报表工具SSRS,但一直没有用过,最近终于需要在工作中一展身手了,于是我特地按照自己的理解做了以下总结: 1. 安装软件结构 SSRS全称SQL Server Re ...

  9. 在每页(分页)报表中重复显示标题 - SQL Server Reporting Service (SSRS)

    问题描述 TFS系统提供多种报表,有图表(Chart).Web面板(Dashboard).SharePoint面板.Excel报表,SQL Server Reporting Serivce(SSRS) ...

随机推荐

  1. 4.传统的MVC

    通过document view设计,我们把应用程序的状态(clicktimes)从一个简单的类设计中抽取出来.下一个目标是抽取转化主要的事件(这个例子里面是鼠标点击之后释放)为应用程序逻辑从而改变应用 ...

  2. 3.3PCL已有点类型介绍和增加自定义的点类型

    1.PCL中有哪些可用的PointT类型 这些point类型都位于point_types.hpp文件中,如果用户需要自己定义类型,需要对已有类型了解. 1)PointXYZ---成员变量:float ...

  3. 使用Eclipse创建Maven javaweb项目

    其实是我自己不会创建Maven JavaWeb项目,就自己瞎蒙了一下,竟然成功了. 这里有个条件就是你的Maven已经在电脑上配好了. 第一步就是File->New->Maven Proj ...

  4. 使用 Bulma

    一.起因 最近我在学习 SASS,通过它,可以将 CSS 像编程语言一样书写. 在最近之前,我又学习了 Flex 布局,用起来很方便. 所以,我学习了 Bulma 这个纯 CSS 框架--使用 Fle ...

  5. 解决Spring MVC 对AOP不起作用的问题

    用的是 SSM3的框架 Spring MVC 3.1 + Spring 3.1 + Mybatis3.1 第一种情况: Spring MVC 和 Spring 整合的时候,SpringMVC的spri ...

  6. malloc/free 与 new/delete同与不同

    一.相同点 1.都是从堆上申请内存,由程序员来掌控这段内存的申请与释放. 2.对于内置类型,两者使用没有太大区别. 二.不同点 1.malloc/free是C++/C语言的标准库函数,需要库支持:ne ...

  7. 获取MS SQL Server用户存储过程最近修改日期

    最近开发一个网站,已经交给用户测试,不过用户反馈有些问题,需要修改.也许修改的存储过程较多.Insus.NET又懒得做些修改记录,在给用户作更新时,能快速找到最近修改过的存储过程,一一作更新即可. 我 ...

  8. Python3下的paramiko模块

    paramiko模块是基于Python实现的SSH远程安全连接,用于SSH远程执行命令.文件传输等功能. 默认Python没有,需要手动安装:pip install paramiko SSH密码认证远 ...

  9. 内容可循环重用的ScrollView

    UIScrollView是iOS中最常用的交互控件之一,本文讨论当设定为翻页模式,内容页很多的时候,如果给每个页面都创建一个新View,会导致资源爆表.比较好的做法是参考UITableViewCell ...

  10. hdu4658(广义五边形&分割函数2)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:f(x) 为将 x 分成其他数和的形式的方案数.对于 t 组输入,输出 f(xi, k), ...