简体   繁体   English

如何在VS2010项目中使用VS 2008中的SSRS ReportViewer?

[英]How can I use the SSRS ReportViewer from VS 2008 in a VS2010 project?

I'm working on an ASP.NET MVC 2 / .NET 3.5 project which includes SSRS 2008 reports. 我正在研究一个包含SSRS 2008报告的ASP.NET MVC 2 / .NET 3.5项目。 After migrating to VS 2010 RC, the new web forms report viewer has been giving so much trouble that I'd like to use the old report viewer from VS 2008 again. 迁移到VS 2010 RC后,新的Web表单报表查看器给您带来了很多麻烦,我想再次使用VS 2008中的旧报表查看器。 Now I'm just wondering what would be the easiest way to do that. 现在我只是想知道什么是最简单的方法。

The report viewer is embedded in a Webforms ASPX file which is loaded in an IFrame by the the MVC view. 报表查看器嵌入在Webforms ASPX文件中,该文件由MVC视图加载到IFrame中。 Report parameters are currently stored as session variables, and for security reasons I would prefer not to change that for HTTP POST or GET parameters. 报表参数当前存储为会话变量,出于安全原因,我希望不要更改HTTP POST或GET参数。 So I can't just put the report viewer in a separate application and build that with VS2008. 因此,我不能只是将报表查看器放在单独的应用程序中并使用VS2008进行构建。

Moving the entire project back to VS 2008 is not an option. 不能将整个项目移回VS 2008。

So, what's the easiest way for me to use the VS 2008 ReportViewer in VS 2010? 那么,在VS 2010中使用VS 2008 ReportViewer的最简单方法是什么? Is there way to grab an assembly from VS 2008 and use that in my project? 有没有办法从VS 2008中获取程序集并将其用于我的项目中?

Thanks, 谢谢,

Adrian 阿德里安

Edit: The problems I am having with the VS2010 version of the ReportViewer are related to AJAX requests. 编辑:我在ReportViewer的VS2010版本中遇到的问题与AJAX请求有关。 For instance, AsyncRendering=True fails to load the report and using the paging controls or the reload button does not work either . 例如, AsyncRendering = True无法加载报告,并且使用分页控件,或者reload按钮也不起作用 The export button works fine, but that's because it's not related to AJAX requests. 导出按钮可以正常工作,但这是因为它与AJAX请求无关。

If you have any idea how I can fix this, I'd really prefer to keep the new report viewer. 如果您知道如何解决此问题,我真的希望保留新的报表查看器。 It's just that I have previously asked about this on SO , on social.msdn.com and on MS Connect and have not found an answer yet. 只是我以前在SO ,social.msdn.com和MS Connect 上询问过此问题,但尚未找到答案。

You have several options depending on the problem(s) you are experiencing. 根据所遇到的问题,您有几种选择。 If one of these suggestions does not work for you, please describe the issues you are having with the control in more detail. 如果这些建议之一对您不起作用,请更详细地描述控件存在的问题。 For example, are you having trouble with the control in the designer, Microsoft changed its functionality or API, or is it misbehaving at runtime? 例如,您是否在设计器中遇到控件问题,Microsoft是否更改了其功能或API,或者在运行时行为异常?

  • If the issue is with the API or the runtime behavior of the report viewer, and if you have both VS 2008 and VS 2010 installed, you can very easily remove the reference to the 2010 version (actually version 10.0) of Microsoft.ReportViewer.WebForms under your project references. 如果问题出在API或报表查看器的运行时行为上,并且同时安装了VS 2008和VS 2010,则可以非常轻松地删除对Microsoft.ReportViewer.WebForms的2010版本(实际上是10.0版)的引用。在您的项目参考下。 Then you can use the add reference dialog to choose the version from 2008 (actually version 9.0). 然后,您可以使用添加引用对话框从2008年选择版本(实际上是9.0版)。 You will also need to update each page that uses the report viewer and replace the version 10 declaration with the version 9 declaration below. 您还需要更新使用报表查看器的每个页面,并用下面的版本9声明替换版本10声明。

On each page replace: 在每页上替换:

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

With: 带有:

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

And in the web.config replace: 并在web.config中替换:

<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />

With: 带有:

<add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

And in the web.config replace: 并在web.config中替换:

<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" />

With: 带有:

<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>

And in the web.config replace: 并在web.config中替换:

<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

With: 带有:

<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  • If only the designer is crashing on you or giving you trouble, you could wrap the 2010 version of the control in a user control or custom control and consume it that way in your pages. 如果只有设计者在您面前崩溃或给您带来麻烦,则可以将控件的2010版本包装在用户控件或自定义控件中,并以这种方式在您的页面中使用。 You will still not have very good designer experience, but if the designer is your issue, this might be the best workaround to avoid crashes or other issues. 您仍然不会有很好的设计师经验,但是如果设计师是您的问题,那么这可能是避免崩溃或其他问题的最佳解决方法。

  • If you still can't get this to work, you could drop back into VS2008 and wrap up the 2008 version of the report viewer in a custom server control. 如果仍然无法执行此操作,则可以退回到VS2008,并在自定义服务器控件中包装报表查看器的2008版本。 You could then reference your new control in your 2010 project. 然后,您可以在2010项目中引用新控件。 Again, you would lose designer support this way. 同样,您将以这种方式失去设计师的支持。

In addition to these steps you should to log into Microsoft Connect and report the trouble you are having in detail, so they can fix it and include it in the RTM of Visual Studio 2010 (or perhaps a patch). 除了这些步骤之外,您还应该登录Microsoft Connect并详细报告所遇到的问题,以便他们可以修复它并将其包含在Visual Studio 2010的RTM中(或可能是补丁程序)。

Brian Hartman has a blog devoted to Report Viewer that covers this very topic: AsyncRendering and all the Baggage that Comes With It 布赖恩·哈特曼(Brian Hartman)的博客致力于Report Viewer,涵盖了以下主题: AsyncRendering及其附带的所有包g

The AsyncRendering property on the ASP.Net ReportViewer control is one of the most misunderstood properties on the ReportViewer. ASP.Net ReportViewer控件上的AsyncRendering属性是ReportViewer上最容易误解的属性之一。 And that's our fault. 那是我们的错。 There are a lot of side effects to setting this property that you wouldn't expect from the name. 设置此属性会产生很多副作用,这是名称所不希望的。 In fact, most of the time that I see users setting this property they are doing it for the side effects rather than for its true intention. 实际上,在大多数情况下,我看到用户设置此属性是因为其副作用而不是其真实意图。 Those side effects are gone in Visual Studio 2010 because you can get the effects you want in either mode. 这些副作用在Visual Studio 2010中消失了,因为您可以在任何一种模式下获得所需的效果。 But to understand how things have changed, let's first go through some background information. 但是,要了解情况是如何变化的,我们首先来看一些背景信息。

The intention of AsyncRendering AsyncRendering的意图

Traditionally, the HTML of a web page is not sent to the browser until all of the web controls on the page have generated their content. 传统上,网页的HTML直到页面上的所有Web控件生成其内容后才发送到浏览器。 For controls such as text boxes and buttons, this makes perfect sense. 对于文本框和按钮之类的控件,这是很有意义的。 But the ReportViewer is much more complicated than that. 但是ReportViewer比这复杂得多。 It can take the viewer a long time to generate the HTML for a report. 查看器需要很长时间才能生成报告的HTML。 In most cases, it makes more sense to send the rest of the page back to the browser and then make another request to get the report content asynchronously. 在大多数情况下,将页面的其余部分发送回浏览器,然后发出另一个请求以异步方式获取报告内容更为有意义。 This allows the user to interact with the rest of the page as well as see a "loading indicator" so that they know the server is doing something. 这使用户可以与页面的其余部分进行交互,并看到“加载指示器”,以便他们知道服务器正在做某事。 This is the default behavior - AsyncRendering = true. 这是默认行为-AsyncRendering = true。

But there are also cases where you want the block the entire page until the report is processed. 但是,在某些情况下,您希望在整个报表之前都将其屏蔽。 A good example is a dashboard type of page that is rendering several small reports, perhaps each one containing a single chart or small table. 一个很好的例子是仪表板类型的页面,该页面呈现多个小报告,也许每个报告都包含一个图表或一个小表。 In this case, you may not want the user to be bombarded with multiple wait indicators. 在这种情况下,您可能不希望用户受到多个等待指示器的轰炸。 If you know the reports are quick to process, blocking the page for a short time may be a better overall experience. 如果您知道报告可以快速处理,则短时间屏蔽页面可能是更好的整体体验。 This is the intention of AsyncRendering = false. 这是AsyncRendering = false的意图。

Asynchronous mode in Visual Studio 2005 and 2008 Visual Studio 2005和2008中的异步模式

The mode you choose has a significant effect on the HTML that is ultimately generated. 您选择的模式对最终生成的HTML有重大影响。 The ReportViewer control was originally designed long before the appearance of ASP.Net AJAX. ReportViewer控件最初是在ASP.Net AJAX出现之前设计的。 When you render a report synchronously, the HTML for the report content is embedded directly in the entire page. 同步呈现报表时,报表内容的HTML直接嵌入到整个页面中。 But when you render asynchronously, the ReportViewer uses a frame. 但是,当您异步呈现时,ReportViewer使用框架。 The frame content is retrieved by the browser separately from the main page, so it allows the main page to be visible while the report is generated in a separate request to the web server. 框架内容是由浏览器与主页分开检索的,因此,在向Web服务器发出的单独请求中生成报告时,它可使主页可见。

Frames are at the root of all of the side effects to AsyncRendering. 框架是AsyncRendering所有副作用的根源。 The use of frames results in the following differences between the two modes: 帧的使用导致两种模式之间存在以下差异:

The document map is only visible in asynchronous mode, in part because it relies on frames to handle resizing relative to the report area. 该文档结构图仅在异步模式下可见,部分原因是它依赖于框架来处理相对于报告区域的大小调整。 Because the report is rendered in a frame and not part of the ASP.Net page that hosts the viewer, there is no chance for developers to handle events that occur while processing the report. 由于报表是在框架中呈现的,而不是承载查看器的ASP.Net页的一部分,因此开发人员没有机会处理在处理报表时发生的事件。 The most frequent complaint we receive in this area is the inability to handle the ReportError event when rendering asynchronously. 我们在此区域收到的最常见的投诉是异步呈现时无法处理ReportError事件。 The size of the frame is difficult for the viewer to calculate and is therefore usually wrong. 观看者难以计算帧的大小,因此通常是错误的。 It's based on the sizing mode of the viewer (percentage or fixed size), the height of the toolbar, and the existence of parameters. 它基于查看器的大小调整模式(百分比或固定大小),工具栏的高度以及参数的存在。 This is the leading cause to seeing an excessive number of scrollbars in the viewer, particularly when using standards mode or non-IE browsers. 这是导致在查看器中看到过多滚动条的主要原因,尤其是在使用标准模式或非IE浏览器时。 Developers often switch to synchronous rendering to alleviate this. 开发人员经常切换到同步渲染来减轻这种情况。 Along a similar line to sizing of the frame is the fact that the SizeToReportContent property is ignored in asynchronous mode. 与调整框架大小相似的是,在异步模式下忽略SizeToReportContent属性。 The frame does not adjust its size based on the content, so there is no easy way to show an arbitrary report embedded in a page without scrollbars, unless you switch to synchronous mode. 该框架不会根据内容调整其大小,因此,除非切换到同步模式,否则没有简单的方法来显示嵌入在没有滚动条的页面中的任意报告。 These side effects tend to rank higher in terms of requirements when building an application than whether the report shows up synchronously. 在构建应用程序时,这些副作用在需求方面的排名往往要高于报告是否同时显示。 So it's no surprise that these issues became the driving factor in which mode developers choose. 因此,这些问题成为开发人员选择模式的驱动因素也就不足为奇了。

The Story in Visual Studio 2010 Visual Studio 2010中的故事

One of the biggest features of the ASP.Net ReportViewer in VS 2010 is the fact that it relies heavily on ASP.Net AJAX. VS 2010中ASP.Net ReportViewer的最大功能之一是它非常依赖ASP.Net AJAX。 By default, the viewer will use asynchronous postbacks for all of its operations. 默认情况下,查看器将对其所有操作使用异步回发。 This means that we no longer need to rely on frames to retrieve report data asynchronously from the rest of the ASP.Net page. 这意味着我们不再需要依赖框架从ASP.Net页面的其余部分异步检索报表数据。 With VS 2010, once a report has finished loading, the HTML displayed in the browser will be the same, regardless of whether you use synchronous or asynchronous rendering. 使用VS 2010,一旦报表加载完成,无论您使用同步还是异步呈现,浏览器中显示的HTML都将相同。

All of the previous side effects of AsyncRendering are now gone. AsyncRendering的所有以前的副作用现在都消失了。 Both modes support the document map. 两种模式都支持文档图。 Both modes support the SizeToReportContent property. 两种模式都支持SizeToReportContent属性。 Asynchronous postbacks are generally treated the same as traditional postbacks, so you can handle events that occur during report processing. 异步回发通常与传统回发相同,因此您可以处理报表处理期间发生的事件。 And because of the extensive work we've put into this release for standards mode HTML and Firefox and Safari rendering, you should never see double (or triple!) scrollbars in the viewer. 由于我们在此版本中为标准模式HTML和Firefox和Safari渲染进行了大量工作,因此您在查看器中永远不会看到双(或三!)滚动条。

With VS 2010, AsyncRendering has returned to its true intention – it controls whether the initial processing of the report blocks the entire ASP.Net page, and nothing else. 在VS 2010中,AsyncRendering已恢复其真实意图–它控制报表的初始处理是否阻止了整个ASP.Net页,并且没有其他任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM