Showing posts with label localreportrender. Show all posts
Showing posts with label localreportrender. Show all posts

Monday, March 19, 2012

LocalReport.Render problem

At the moment my Intranet contains a few reports which are all shown using one reportviewer. I use this bit of code to switch one RDLC for another

===

ReportViewer1.LocalReport.DataSources.Clear();

ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsstrafstudie_DataTable1","ObjectDataSource2"));

ReportViewer1.LocalReport.ReportPath = "rptstrafstudie.rdlc";

ObjectDataSource2.FilterExpression = "datum = '" + Request.QueryString["datum"]+ "'";

===

It works just fine ! Now I Want to skip the reportviewer VIEW and just let the people download EXCEL or PDF export. So I add this bit of code

===

Warning[] warnings;

string[] streamids;

string mimeType;

string encoding;

string extension;

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

FileStream fs = new FileStream(@."c:\output.xls", FileMode.Create);

fs.Write(bytes, 0, bytes.Length);

fs.Close();

===

But I keep getting the error "A data source instance has not been supplied for the data source "dsstrafstudie_DataTable1". Alltough I DO supply a DS instance only a few rules above ? What on earth am I doing wrong?

Thx in advance,

Puitje

Hi Puitje,

Did you find a solution for this error? I am experiencing the exact problem.

Thanks

|||Instead of using "ReportViewer1.LocalReport" create a new instance of a LocalReport and use that one.|||

I use a new variable LocalReport rp1, but error doesn't change ...

If i didin't use a datasource for the report the code works correctly.

Someone have any idea ?

Thanks

|||Did you add the datasource when you used Render?|||

Yes cause i copy the same code that visualize the Report correctly and i put it in a new function.

The function who render at video works correctly, the function who render manually give me the exception.

|||Are you sure that the objectdatasource you provided is correctly populated? Maybe you lost some event that populates it?|||I

I post the code :


these two function are called on Page_Load event ( the same on Page_PreRender).

The first function works correctly and display on my page the report with correct data.

The second function generate an exception on Render call.

He didn't find "DataforReport" istance.

The rdlc is a converted rdl.

FIRST

virtual public Boolean VisualizzaReport(ref Hashtable par)
{
ReportViewer rp1;
ReportDataSource ds1;
SqlDataSource sql1;
Database dbRep;
ControlParameter cp1;
Label l1;

// Definisce l'SqlDataSource per poi definire il ReportDataSource in funzione di questo
sql1 = new SqlDataSource();
sql1.ID = ReportPage.PageContent.SqlReportSource.ToString();
dbRep = new Database(this.NomeDatabase, this.NomeSP, ref sql1, 0);
sql1.SelectParameters.Clear();

foreach (DictionaryEntry de in par)
{
l1 = new Label();
l1.ID = "Label_"+de.Key.ToString();
l1.Text=de.Value.ToString();
l1.Visible = false;
this.content.Controls.Add(l1);

cp1 = new ControlParameter();
cp1.ControlID = l1.ID = "Label_" + de.Key.ToString();
cp1.Name = de.Key.ToString();
cp1.PropertyName = "Text";
cp1.Type = Type.GetTypeCode(de.Value.GetType());
// TypeCode.Int32;
sql1.SelectParameters.Add(cp1);
}
this.content.Controls.Add(sql1);
// Definisce il reportDataSource
ds1 = new ReportDataSource();
ds1.Name = "DataforReport";
ds1.DataSourceId = ReportPage.PageContent.SqlReportSource.ToString();

// Definisce il Report
rp1 = new ReportViewer();
rp1.ID = ReportPage.PageContent.ReportLocale.ToString();
rp1.ShowToolBar = false;
rp1.Width = new Unit(100, UnitType.Percentage); ;
rp1.Height = new Unit(100, UnitType.Percentage); ;
//rp1.ID = ReportPage.PageContent.ReportLocale.ToString();
rp1.LocalReport.DisplayName = this.NomeReport;
rp1.LocalReport.ReportPath = this.NomefileReport;
rp1.LocalReport.DataSources.Clear();
rp1.LocalReport.DataSources.Add(ds1);
rp1.LocalReport.Refresh();
this.content.Controls.Add(rp1);

return true;
}

SECOND

virtual public Boolean RenderReport(ref Hashtable par)
{
ReportViewer rp1;
ReportDataSource ds1;
SqlDataSource sql1;
Database dbRep;
ControlParameter cp1;
Label l1;

sql1 = new SqlDataSource();
sql1.ID = ReportPage.PageContent.SqlReportSource.ToString();
dbRep = new Database(this.NomeDatabase, this.NomeSP, ref sql1, 0);
sql1.SelectParameters.Clear();

foreach (DictionaryEntry de in par)
{
l1 = new Label();
l1.ID = "Label_" + de.Key.ToString();
l1.Text = de.Value.ToString();
l1.Visible = false;
this.content.Controls.Add(l1);

cp1 = new ControlParameter();
cp1.ControlID = l1.ID = "Label_" + de.Key.ToString();
cp1.Name = de.Key.ToString();
cp1.PropertyName = "Text";
cp1.Type = Type.GetTypeCode(de.Value.GetType());
// TypeCode.Int32;
sql1.SelectParameters.Add(cp1);
}
this.content.Controls.Add(sql1);
// Definisce il reportDataSource
ds1 = new ReportDataSource();
ds1.Name = "DataforReport" ;
ds1.DataSourceId = ReportPage.PageContent.SqlReportSource.ToString();

ReportViewer rp2;
rp2 = new ReportViewer();
rp2.LocalReport.ReportPath = "Fattura.rdlc";
rp2.LocalReport.DataSources.Clear();
rp2.LocalReport.DataSources.Add(ds1);
string deviceInfo =

"<DeviceInfo>" +

" <OutputFormat>PDF</OutputFormat>" +

" <PageWidth>8.5in</PageWidth>" +

" <PageHeight>11in</PageHeight>" +

" <MarginTop>0.5in</MarginTop>" +

" <MarginLeft>1in</MarginLeft>" +

" <MarginRight>1in</MarginRight>" +

" <MarginBottom>0.5in</MarginBottom>" +

"</DeviceInfo>";
byte[] data =rp2.LocalReport.Render("PDF", deviceInfo, out mimeType,out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(@."c:\prova.pdf", FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
//determine if format is rendered to the web or a file.

return true;
}

|||Why do you define 2 datasources? When do you add data to ds1?|||I think the refresh method in the first code triggers the datasource updating...

LocalReport.Render does not return

Sorry for the cross-post, but I'm not sure what the best place to post this
is, and I'm getting a bit desparate.
Part of our product uses the SQL Server Reporting engine to create reports
in Excel and PDF format. To do this I am using the LocalReport object the
Microsoft.ReportViewer.WinForms namespace. This is all running in a
web-based service running in IIS.
In development and UAT this has worked flawlessly and had been very powerful
and convenient. Having just put some of our systems live, we are suddenly
running into problems that I am unable to work out how to resolve.
Everything works fine at first, but after the service has been running for
between 20 and 40 minutes, suddenly the report generation stops working.
I've added debug logging to the application, and can see that the last
statement that gets executed is a call to the LocalReport.Render method.
This never returns.
If we recycle the application pool, the reports start working again -- for
another 20 to 40 minutes. Then they stop, just as before.
Setting the application pools to automatically recycle every 20 minutes
seems like a very bad solution to this. I would really like to understand
why it is that the system is locking up. But without being able to step into
the source code for the LocalReport object, I'm completely at a loss as to
how I can resolve this.
Does anyone have any suggestions as to what I could try?
We're using VS2005 and ASP.NET v2.0, running in IIS6 on Windows Server 2003.
My thanks in advance,
--
(O)enoneHave you tried using the WebForms version? Usually when there are a WinForms
and WebForms versions of the same item it's due to the fact that the
WinForms version will not run in the ASP.Net threading model, or uses
services that are not applicable in that environment.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199...2006
"Oenone" <oenone@.nowhere.com> wrote in message
news:eLhRw6PVHHA.4756@.TK2MSFTNGP06.phx.gbl...
> Sorry for the cross-post, but I'm not sure what the best place to post
> this is, and I'm getting a bit desparate.
> Part of our product uses the SQL Server Reporting engine to create reports
> in Excel and PDF format. To do this I am using the LocalReport object the
> Microsoft.ReportViewer.WinForms namespace. This is all running in a
> web-based service running in IIS.
> In development and UAT this has worked flawlessly and had been very
> powerful and convenient. Having just put some of our systems live, we are
> suddenly running into problems that I am unable to work out how to
> resolve.
> Everything works fine at first, but after the service has been running for
> between 20 and 40 minutes, suddenly the report generation stops working.
> I've added debug logging to the application, and can see that the last
> statement that gets executed is a call to the LocalReport.Render method.
> This never returns.
> If we recycle the application pool, the reports start working again -- for
> another 20 to 40 minutes. Then they stop, just as before.
> Setting the application pools to automatically recycle every 20 minutes
> seems like a very bad solution to this. I would really like to understand
> why it is that the system is locking up. But without being able to step
> into the source code for the LocalReport object, I'm completely at a loss
> as to how I can resolve this.
> Does anyone have any suggestions as to what I could try?
> We're using VS2005 and ASP.NET v2.0, running in IIS6 on Windows Server
> 2003.
> My thanks in advance,
> --
> (O)enone
>|||Mark Fitzpatrick wrote:
> Have you tried using the WebForms version?
Hmm, interesting, no I haven't.
The application in question can potentially be driven from both a web
service and also a Windows Forms application (it's implemented in a separate
DLL that can be used in either environment). I initially wrote it all in the
WinForms environment, and hence by the time I got to running it from the web
I'd forgotten all about the existence of the WebForms version.
As we're only using it to programmatically generate the report content
(we're not using the report viewer control at all), I just assumed that the
WinForms version would work correctly in both environments.
Anyway, I've rebuilt the application using the WebForms version of the DLL
(which was nice and easy), and have deployed that to our productions server,
now I just need to wait and see if it makes a difference. I'll post back
with the results.
Thanks for giving me something else to try! :)
--
(O)enone|||Oenone wrote:
>> Have you tried using the WebForms version?
> Hmm, interesting, no I haven't.
Sadly this has exactly the same problem as the WinForms version. After
working fine for a little while, it ultimately stops returning each time it
is called.
Any other suggestions?
--
(O)enone

LocalReport.Render creates PDFs 10x the size of RS 2000

I'm using LocalReport.Render to create PDFs from my VB.Net 2005 application.
The resulting PDF is about 10x the size of the same report rendered from RS
2000. Looking inside the generated PDF file, I see that the main body of the
report is no longer using any compression.
Is there any way to force LocalReport.Render to use the compression that RS
2000 was using?This is a known bug:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=134219&SiteID=1
--
Robert Jeppesen
Durius
http://www.durius.com/
"davedave" <davedave@.discussions.microsoft.com> wrote in message
news:7929FEFC-3427-4864-A817-B3A83269F92D@.microsoft.com...
> I'm using LocalReport.Render to create PDFs from my VB.Net 2005
> application.
> The resulting PDF is about 10x the size of the same report rendered from
> RS
> 2000. Looking inside the generated PDF file, I see that the main body of
> the
> report is no longer using any compression.
> Is there any way to force LocalReport.Render to use the compression that
> RS
> 2000 was using?