报告生成器 3.0 与 VS2010 错误

发布于 2024-11-01 11:17:10 字数 3510 浏览 6 评论 0原文

我使用 Report Builder 3.0 构建了一个报告,并尝试使用 VS 2010 中的报告查看器显示它。我不断收到此错误消息。

报告定义无效。详细信息:报表定义具有无效的目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition”,无法升级。

这是我正在使用的代码。

public partial class ViewReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            PopulateReport(GetDataSet("24"), Server.MapPath("/IncidentReportOld.rdl"));
    }
    private DataSet GetDataSet(string id)
    {
        string sql = string.Empty;
        SqlDataAdapter ada;
        string conString = "Data Source=con-sqlc-02;Initial Catalog=Incident;Integrated Security=True";

        DataSet ds = new DataSet();

        sql = "select * from Rpt_Incident where incidentID = " + id;
        ada = new SqlDataAdapter(sql, conString);
        ada.Fill(ds, "Incidents");

        return ds;
    }

    private void PopulateReport(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            ReportViewer rv = new ReportViewer();
            rv.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            rv.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                rv.LocalReport.DataSources.Add(datasource);
            }

            RenderPDF(rv);
        }
    }

    private void RenderPDF(ReportViewer rv)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;

        byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

        this.Page.Response.ClearHeaders();
        this.Page.Response.AddHeader("content-disposition", "inline; filename=IncidentTest.pdf");
        this.Page.Response.ClearContent();
        this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
        this.Page.Response.ContentType = "application/pdf";

        BinaryWriter writer = new BinaryWriter(this.Page.Response.OutputStream);
        writer.Write(bytes);

        writer.Close();

        //flush and close the response object
        this.Page.Response.Flush();
        this.Page.Response.Close();
    }
    private void PopulateReport1(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            //ReportViewer rv = new ReportViewer();
            ReportViewer1.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            ReportViewer1.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                ReportViewer1.LocalReport.DataSources.Add(datasource);
            }

            ReportViewer1.LocalReport.Refresh();
            //RenderPDF(rv);
        }
    }


}

I built a report with Report Builder 3.0 and I am trying to display it with a report viewer in VS 2010. I keep getting this error message.

The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition' which cannot be upgraded.

Here is the code I am using.

public partial class ViewReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            PopulateReport(GetDataSet("24"), Server.MapPath("/IncidentReportOld.rdl"));
    }
    private DataSet GetDataSet(string id)
    {
        string sql = string.Empty;
        SqlDataAdapter ada;
        string conString = "Data Source=con-sqlc-02;Initial Catalog=Incident;Integrated Security=True";

        DataSet ds = new DataSet();

        sql = "select * from Rpt_Incident where incidentID = " + id;
        ada = new SqlDataAdapter(sql, conString);
        ada.Fill(ds, "Incidents");

        return ds;
    }

    private void PopulateReport(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            ReportViewer rv = new ReportViewer();
            rv.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            rv.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                rv.LocalReport.DataSources.Add(datasource);
            }

            RenderPDF(rv);
        }
    }

    private void RenderPDF(ReportViewer rv)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;

        byte[] bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

        this.Page.Response.ClearHeaders();
        this.Page.Response.AddHeader("content-disposition", "inline; filename=IncidentTest.pdf");
        this.Page.Response.ClearContent();
        this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
        this.Page.Response.ContentType = "application/pdf";

        BinaryWriter writer = new BinaryWriter(this.Page.Response.OutputStream);
        writer.Write(bytes);

        writer.Close();

        //flush and close the response object
        this.Page.Response.Flush();
        this.Page.Response.Close();
    }
    private void PopulateReport1(DataSet ds, string reportPath)
    {
        /* Put the stored procedure result into a dataset */

        if (ds.Tables[0].Rows.Count == 0)
        {
            //lblMessage.Text = "Sorry, no record returned in this report";
        }
        else
        {

            // Set ReportViewer1
            //ReportViewer rv = new ReportViewer();
            ReportViewer1.LocalReport.ReportPath = reportPath;
            ReportDataSource datasource;
            ReportViewer1.LocalReport.DataSources.Clear();
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                datasource = new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]);
                ReportViewer1.LocalReport.DataSources.Add(datasource);
            }

            ReportViewer1.LocalReport.Refresh();
            //RenderPDF(rv);
        }
    }


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

要走就滚别墨迹 2024-11-08 11:17:10

我实际上能够自己解决这个问题。

我刚刚将扩展名从 RDL 更改为 RDLC。然后我在VS中打开它,VS问我是否要转换它。我说是,然后我收到了此错误消息。

报表定义具有无效的目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition”,无法升级。

因此,我将命名空间更改为 SQL Reporting Services 2008 的命名空间。

<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">

之后,我收到一条错误消息,指出“ReportSections”是无效的子元素。我删除了它然后一切正常!希望这能帮助其他人解决这个问题。

I was actually able to fix this issue myself.

I just changed the extension from RDL to RDLC. Then I opened it in VS and VS asked me if I wanted to convert it. I said yes then I got This error message.

The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition' which cannot be upgraded.

So I changed the namespace to this which is for SQL Reporting Services 2008.

<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">

After that I got an error saying "ReportSections" is an invalid child element. I removed it then everything worked! Hopefully this will help anyone else with this issue.

顾北清歌寒 2024-11-08 11:17:10

我通过将 Microsoft.ReportViewer.CommonMicrosoft.ReportViewer.WinForms 的特定版本属性更改为 false 在我的 winforms 项目中修复了此问题参考

I fixed this issue in my winforms project by changing the Specific version property of Microsoft.ReportViewer.Common and Microsoft.ReportViewer.WinForms to false in References

醉生梦死 2024-11-08 11:17:10

我也遇到了同样的问题,但你的解决方案对我不起作用。我正在使用 VS 2013 Express 并使用 ReportBuilder 3.0。我在 msdn 论坛上看到,使用 ReportBuilder2.0 可以解决该问题,他们是对的。因此,请尝试使用报表生成器 2.0。

I've had the same problem, but your solution didn't work for me. I'm using VS 2013 express and USED to use ReportBuilder 3.0. I've seen on the msdn forums that using ReportBuilder2.0 will resolve that issue and they were right. So try using Report Builder 2.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文