最近在做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 Services 自定义数据处理扩展DPE(Data Processing Extension)的更多相关文章

  1. SQL Server Reporting Service(SSRS) 第五篇 自定义数据处理扩展DPE(Data Processing Extension)

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

  2. 充分利用 SQL Server Reporting Services 图表

    最近在查SSRS的一些文章,看到MSDN在有一篇不错的文章,许多图表设置都有说明,共享给大家.. 其中有说明在SSRS中如果去写条件表达写和报表属性中的“自定义代码”,文章相对比较长,需要大家耐心的查 ...

  3. SQL Server Reporting Services本机模式下的权限管理

    SQL Server Reporting Services在安装配置后,缺省只给BUILTIN\Administrators用户组(实际上只有本机的Administrator用户)提供管理权限.所以所 ...

  4. SrsDataConnector The SQL Server Reporting Services account is a local user and is not supported.

    这次使用OS+SQL的镜像还原系统后安装了CRM 2015,主要流程是 安装IIS/AD,SSRS ,CRM2015.自带的SQL中SSRS没有安装完全,需配置一下. 这一切都满顺利的,最后在安装 S ...

  5. SQL Server Reporting Services – Insufficient Rights Error

    http://www.sql-server-performance.com/2011/security-ssrs-reporting-error/ SQL Server Reporting Servi ...

  6. Incorporating ASP.NET MVC and SQL Server Reporting Services, Part 1

    Your ASP.NET MVC application needs reports. What do you do? In this article, I will demonstrate how ...

  7. SQL Server Reporting Services (SQLEXPRESS) 服务占用80端口

    win7, 好多时候,看到system进程占用了80端口,这个是系统进程,不能直接结束.我们不知道这个进程的哪个服务占用了80端口,这里记录其中一个服务"SQL Server Reporti ...

  8. [转]SQL Server Reporting Services - Timeout Settings

    本文转自:https://social.technet.microsoft.com/wiki/contents/articles/23508.sql-server-reporting-services ...

  9. Microsoft Dynamics CRM 2013 安装 报表服务出现“ SQL Server Reporting Services 帐户是本地用户且不受支持 ”错误的解决方法

    安装好CRM 2013 之后,还需要安装报表服务,发现出现:SQL Server Reporting Services 帐户是本地用户且不受支持,具体如下图: 经过分析原来发现是需要用域用户,打开对应 ...

随机推荐

  1. js事件流、事件处理程序/事件侦听器

    1.事件流 事件冒泡 IE的事件流叫做事件冒泡(event bubbling),即事件开始时由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播到较为不具体的节点(文档). 事件捕获 ...

  2. WIFI破解总结

    寒假回家了,由于家里没有宽带,而周围又有好多WIFI所以尝试了破解人家的WIFI,嘻嘻. 1.准备u盘一个,格式化 2.用制作工具,将cdlinux系统的镜像安装进u盘 3.用u盘启动电脑,进入cdl ...

  3. 【WPF】逻辑树和视觉树

    WPF中提供了遍历逻辑树和视觉树的辅助类:System.Windows.LogicalTreeHelper和 System.Windows.Media.VisualTreeHelper. 注意遍历的位 ...

  4. 重复数据插入unique列时,锁加在哪?

    1.测试目的 当插入重复数据到有unique索引的表中时,采用何种加锁机制. 2.测试思路 利用10046确定是什么操作导致加锁阻塞了进程: dump锁定前最近一次操作的块结构来分析加锁机制. 3.测 ...

  5. sql server2005主从数据库同步配置

    网站规模到了一定程度之后,该分的也分了,该优化的也做了优化,但是还是不能满足业务上对性能的要求:这时候我们可以考虑使用主从库.主从库是两台服务器上的两个数据库,主库以最快的速度做增删改操作+最新数据的 ...

  6. UIlabel - 富文本属性

    1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...

  7. OC修饰词 - 内存管理

    <招聘一个靠谱的 iOS>—参考答案(上) 说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均 ...

  8. android开发环境重装系统之后的配置

    前提: 之前配置好的android开发环境:重装系统:压缩了android目录 配置: 安装java环境 安装; 建立JAVA_HOME变量:JAVAHOME添加到path变量 JAVA_HOME=C ...

  9. LightOj_1364 Expected Cards

    题目链接 题意: 一副牌, 每个花色13张牌,加上大小王,共54张. 遇到大小王可以代替其中某种花色. 给定C, D, H, S. 每次抽一张牌, 问抽到C张梅花, D张方块, H张红桃, S张黑桃所 ...

  10. VIM一些常用命令,方法,配置

    配置文件地址 github 工具只是为了更好的工具,选择一种,坚持使用学习记忆,熬过瓶颈期就可以了. 现在我基本大的项目是IDE+vim 插件,写小代码是VIM. 常用的操作,便捷的方法 1.如何选中 ...