从SQL Server 2005 Reporting Services报告中调用.Net程序集?

时间:2021-10-24 08:09:03

I've currently got a set of reports with a number of common functions sitting in code blocks within the .rdl files. This obviously presents a maintainability issue and I as wondering if anyone knew a way for these different reports to share a library of common code?

我目前有一组报告,其中包含许多常用函数,这些函数位于.rdl文件中的代码块中。这显然是一个可维护性问题,我想知道是否有人知道这些不同的报告共享公共代码库的方法?

Ideally I'd like to have a .Net Assembly attached to my Reporting Services project, which all of my reports can access and call functions from. This would save the headache of trying to update and redeploy about 100 reports every time a change needs to be made to a common function.

理想情况下,我希望将.Net程序集附加到我的Reporting Services项目,我的所有报告都可以访问和调用函数。这样可以避免每次需要对常用功能进行更改时尝试更新和重新部署大约100个报告的麻烦。

Any suggestions?

5 个解决方案

#1


5  

From within Visual Studio in the properties of the report, on the 'References' tab add the details for the assembly that contains the managed code. This code can be called from expressions within reports using the instance name that is specified.

在Visual Studio中的报表属性中,在“引用”选项卡上添加包含托管代码的程序集的详细信息。可以使用指定的实例名称从报表中的表达式调用此代码。

This assembly can either be stored in the GAC or the PrivateAssemblies directory of Visual Studio, and be deployed to the Report Service 'bin' directory on the Reporting Services server. For more information refer to How to use custom assemblies or embedded code in Reporting Services

此程序集可以存储在Visual Studio的GAC或PrivateAssemblies目录中,并部署到Reporting Services服务器上的Report Service'bin'目录。有关更多信息,请参阅如何在Reporting Services中使用自定义程序集或嵌入代码

#2


2  

I had a lot of pain with this so I hope this helps someone. You can get it from the MSDN article but there are a few points below that I think can help speed someone through this a little faster.

我对此感到非常痛苦,所以我希望这对某人有所帮助。您可以从MSDN文章中获取它,但我认为可以帮助加速某人加快速度。

Don't forget to add this to your rssrvpolicy.config file:

不要忘记将其添加到rssrvpolicy.config文件中:

<CodeGroup class="UnionCodeGroup"
   version="1"
   PermissionSetName="FullTrust"
   Name="MyCodeGroup"
   Description="Code group for my data processing extension">
      <IMembershipCondition class="UrlMembershipCondition"
         version="1"
         Url="C:\pathtocustomassembly\customassembly.dll"
       />
</CodeGroup>

I forgot to do this and I was hating it for awhile.

我忘记这样做,我讨厌它一段时间。

Plus don't forget to hit both of the following folders for 2005 with your new dll:

另外,不要忘记使用新的dll点击2005年的以下两个文件夹:

Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies 
Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin

Plus don't use log4net with your assembly. I couldn't make it work. Maybe someone can but not me.

另外,不要在程序集中使用log4net。我无法让它发挥作用。也许有人可以,但不是我。

Plus if you mess up like I did you won't be able to delete the files until you close Visual Studio.

另外,如果你像我一样搞砸了,在关闭Visual Studio之前,你将无法删除这些文件。

Plus make your methods shared or static. It's easier.

加上你的方法共享或静态。这更容易。

Create a deployment batch file. Something like:

创建部署批处理文件。就像是:

@ECHO OFF
REM   Name: SRSDeploy_Local.bat
REM
REM   This batch files copies my custom assembly to my Reporting Services folders.
REM
REM   This is the SQL Server 2005 version:
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\bin"  

Finally, build your report before previewing.

最后,在预览之前构建报告。

If it builds you're likely on your way.

如果它建立你可能在你的路上。

Except...

You can't deploy it to your production report server because you'll always get the following error:

您无法将其部署到生产报表服务器,因为您将始终收到以下错误:

Error while loading code module

加载代码模块时出错

Which is what I'm working on right now.

这就是我现在正在做的事情。

#3


1  

The following article lists just about all the different ways of calling .Net code from an SSRS report. Extending Microsoft SQL Server 2000 Reporting Services with Custom Code

以下文章列出了从SSRS报告中调用.Net代码的所有不同方法。使用自定义代码扩展Microsoft SQL Server 2000 Reporting Services

If all these reports run against the same server, another option to consider would be to use .Net stored procedures in the database to hold your code.

如果所有这些报告都针对同一服务器运行,则需要考虑的另一个选项是使用数据库中的.Net存储过程来保存代码。

#4


1  

Many thanks guys, I can now call my assembly from my reports.

非常感谢你们,我现在可以从我的报告中召集我的大会。

Supplementary question: Is there a namespace I can include when I'm creating my assembly that makes it aware of objects in the report designer such as fields and parameters? It'd be really great if I could pass, say, a collection of fields in a strongly-typed way to my assembly.

补充问题:当我创建程序集时,是否存在可以包含的命名空间,使其能够识别报表设计器中的对象(如字段和参数)?如果我能以强烈的方式将一系列领域传递给我的大会,那真的很棒。

And the answer: A couple of hours of searching reveals that adding \Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\Microsoft.ReportingServices.ProcessingObjectModel.dll as a reference in my assembly allows me to access the various Reporting Services types, such as Fields and Parameters. Note that in Reporting Services 2008, the namespace changes.

答案是:几个小时的搜索显示在我的程序集中添加\ Program Files \ Microsoft Visual Studio 8 \ Common7 \ IDE \ PrivateAssemblies \ Microsoft.ReportingServices.ProcessingObjectModel.dll作为参考允许我访问各种Reporting Services类型,例如字段和参数。请注意,在Reporting Services 2008中,命名空间会更改。

#5


0  

You must deploy to the GAC. http://www.developerdotstar.com/community/node/333

您必须部署到GAC。 http://www.developerdotstar.com/community/node/333

#1


5  

From within Visual Studio in the properties of the report, on the 'References' tab add the details for the assembly that contains the managed code. This code can be called from expressions within reports using the instance name that is specified.

在Visual Studio中的报表属性中,在“引用”选项卡上添加包含托管代码的程序集的详细信息。可以使用指定的实例名称从报表中的表达式调用此代码。

This assembly can either be stored in the GAC or the PrivateAssemblies directory of Visual Studio, and be deployed to the Report Service 'bin' directory on the Reporting Services server. For more information refer to How to use custom assemblies or embedded code in Reporting Services

此程序集可以存储在Visual Studio的GAC或PrivateAssemblies目录中,并部署到Reporting Services服务器上的Report Service'bin'目录。有关更多信息,请参阅如何在Reporting Services中使用自定义程序集或嵌入代码

#2


2  

I had a lot of pain with this so I hope this helps someone. You can get it from the MSDN article but there are a few points below that I think can help speed someone through this a little faster.

我对此感到非常痛苦,所以我希望这对某人有所帮助。您可以从MSDN文章中获取它,但我认为可以帮助加速某人加快速度。

Don't forget to add this to your rssrvpolicy.config file:

不要忘记将其添加到rssrvpolicy.config文件中:

<CodeGroup class="UnionCodeGroup"
   version="1"
   PermissionSetName="FullTrust"
   Name="MyCodeGroup"
   Description="Code group for my data processing extension">
      <IMembershipCondition class="UrlMembershipCondition"
         version="1"
         Url="C:\pathtocustomassembly\customassembly.dll"
       />
</CodeGroup>

I forgot to do this and I was hating it for awhile.

我忘记这样做,我讨厌它一段时间。

Plus don't forget to hit both of the following folders for 2005 with your new dll:

另外,不要忘记使用新的dll点击2005年的以下两个文件夹:

Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies 
Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin

Plus don't use log4net with your assembly. I couldn't make it work. Maybe someone can but not me.

另外,不要在程序集中使用log4net。我无法让它发挥作用。也许有人可以,但不是我。

Plus if you mess up like I did you won't be able to delete the files until you close Visual Studio.

另外,如果你像我一样搞砸了,在关闭Visual Studio之前,你将无法删除这些文件。

Plus make your methods shared or static. It's easier.

加上你的方法共享或静态。这更容易。

Create a deployment batch file. Something like:

创建部署批处理文件。就像是:

@ECHO OFF
REM   Name: SRSDeploy_Local.bat
REM
REM   This batch files copies my custom assembly to my Reporting Services folders.
REM
REM   This is the SQL Server 2005 version:
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"
copy "C:\Projects\Common\lib\SCI.Common.SSRSUtils.dll" "C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\bin"  

Finally, build your report before previewing.

最后,在预览之前构建报告。

If it builds you're likely on your way.

如果它建立你可能在你的路上。

Except...

You can't deploy it to your production report server because you'll always get the following error:

您无法将其部署到生产报表服务器,因为您将始终收到以下错误:

Error while loading code module

加载代码模块时出错

Which is what I'm working on right now.

这就是我现在正在做的事情。

#3


1  

The following article lists just about all the different ways of calling .Net code from an SSRS report. Extending Microsoft SQL Server 2000 Reporting Services with Custom Code

以下文章列出了从SSRS报告中调用.Net代码的所有不同方法。使用自定义代码扩展Microsoft SQL Server 2000 Reporting Services

If all these reports run against the same server, another option to consider would be to use .Net stored procedures in the database to hold your code.

如果所有这些报告都针对同一服务器运行,则需要考虑的另一个选项是使用数据库中的.Net存储过程来保存代码。

#4


1  

Many thanks guys, I can now call my assembly from my reports.

非常感谢你们,我现在可以从我的报告中召集我的大会。

Supplementary question: Is there a namespace I can include when I'm creating my assembly that makes it aware of objects in the report designer such as fields and parameters? It'd be really great if I could pass, say, a collection of fields in a strongly-typed way to my assembly.

补充问题:当我创建程序集时,是否存在可以包含的命名空间,使其能够识别报表设计器中的对象(如字段和参数)?如果我能以强烈的方式将一系列领域传递给我的大会,那真的很棒。

And the answer: A couple of hours of searching reveals that adding \Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\Microsoft.ReportingServices.ProcessingObjectModel.dll as a reference in my assembly allows me to access the various Reporting Services types, such as Fields and Parameters. Note that in Reporting Services 2008, the namespace changes.

答案是:几个小时的搜索显示在我的程序集中添加\ Program Files \ Microsoft Visual Studio 8 \ Common7 \ IDE \ PrivateAssemblies \ Microsoft.ReportingServices.ProcessingObjectModel.dll作为参考允许我访问各种Reporting Services类型,例如字段和参数。请注意,在Reporting Services 2008中,命名空间会更改。

#5


0  

You must deploy to the GAC. http://www.developerdotstar.com/community/node/333

您必须部署到GAC。 http://www.developerdotstar.com/community/node/333