vb.net windows窗体加载报告失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23062162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:22:07  来源:igfitidea点击:

windows forms load report failed

vb.netwinformscrystal-reports

提问by user3531867

I am developing a Windows Form application using Visual Studio 2010 and framework 4.0. I have a number of reports that this application will use.

我正在使用 Visual Studio 2010 和框架 4.0 开发 Windows 窗体应用程序。我有许多此应用程序将使用的报告。

My solution is divided up into folders so that I can keep my files organized. I have a process in one folder that is trying to load the Crystal Report located in another folder.

我的解决方案分为多个文件夹,以便我可以保持文件井井有条。我在一个文件夹中有一个进程试图加载位于另一个文件夹中的 Crystal Report。

When I try to load the report file, I get an error "Load Report Failed". A Google search says it either cannot find the file or the folder does not have permission to access it. Since this is a WinForms application, I do not think the permissions have anything to do with the error since this application and all its folders are included in the overall assembly. I have tried - in debug mode - to use difference file naming to include the folder using just about every combination I can think of but to no avail.

当我尝试加载报告文件时,出现错误“加载报告失败”。谷歌搜索说它要么找不到文件,要么文件夹没有访问它的权限。由于这是一个 WinForms 应用程序,我认为权限与错误没有任何关系,因为该应用程序及其所有文件夹都包含在整个程序集中。我已经尝试过 - 在调试模式下 - 使用差异文件命名来包含我能想到的几乎所有组合的文件夹,但无济于事。

I cannot see why the error occurs. Any clues?

我看不出为什么会发生错误。有什么线索吗?

        Dim rpt As New ReportDocument
        With rpt
            .Load("Form1500_0212.rpt")
            .SetParameterValue(0, bID)
            .SetParameterValue(1, ProviderID)
            .VerifyDatabase()

        End With
        Dim frm As New frmViewReport()
        frm.ShowDialog()

回答by Codemunkeee

there are a lot of possibilities why this is happening..

为什么会发生这种情况有很多可能性..

first, try to specify the full filepath for this line of code

首先,尝试为这行代码指定完整的文件路径

.Load("fullfilepath") 
'e.g., "C:\EmailSys-Phase2\Code\EmailSystem1\xtalReport.rpt"

second, have you installed the runtimes for crystal reports? You can get it here

其次,您是否安装了水晶报表的运行时?你可以在这里得到

third, have you tried adding this on your app.configfile?

第三,你有没有试过在你的app.config文件中添加这个?

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

fourth, try checking if your target frameworkis set to .NET Framework 4.0AND NOT.NET Framework 4.0 Client Profile(I think you're okay with this step already)

第四,尝试检查您target framework是否设置为.NET Framework 4.0AND NOT.NET Framework 4.0 Client Profile(我认为您已经可以完成此步骤)

回答by user3531867

I also discovered that you need to change the property for "Copy to Output Directory" needs to be set to "Copy Always" so that the report definition is available in the executable path. Now my code works with this

我还发现您需要将“复制到输出目录”的属性更改为“始终复制”,以便报告定义在可执行路径中可用。现在我的代码适用于此

 With rpt
    .Load(Application.StartupPath + "\Form1500_0212.rpt")
    .SetParameterValue(0, bID)
    .SetParameterValue(1, ProviderID)
 End With