开发者

Report Builder 3.0 With VS2010 Error

开发者 https://www.devze.com 2023-02-25 04:28 出处:网络
I built a report with Report Builder 3.0 and I am trying to display it with a report view开发者_JAVA百科er in VS 2010. I keep getting this error message.

I built a report with Report Builder 3.0 and I am trying to display it with a report view开发者_JAVA百科er 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);
        }
    }


}


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号