|
I understand the C# code written here.
I use Stored Procedures all the time in SQLServer 2005.
However, I have never deployed C# code.
Can someone give me some hints on taking what Sivakumar has given us and getting it implemented on our SQLServer 2005?
I plan to add it or integrate it with an e-mailing stored procedure I have.
|
|
|
|
|
"Step 2: Add a web reference to the web services exposed by Reporting Services 2005, i.e., ReportExecution2005 and ReportService2005."
Can you give any example of url to the reporting service. I've published a report and can browse it i IE7 with this url: http://n29769:8080/Reports/Pages/Report.aspx?ItemPath=%2fReport+Project1%2fUsers[^]
but get "The URI prefix is not recognized" when try to add a Web Reference in VS2008
_____________________________
...and justice for all
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ReportServerProject
{
class MyReportRenderer
{
private rs2005.ReportingService2005 rs;
private rs2005Execution.ReportExecutionService rsExec;
public void renderTest()
{
rs = new rs2005.ReportingService2005();
rsExec = new rs2005Execution.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://<servername>/ReportServer/ReportService2005.asmx";
rsExec.Url = "http://<servername>/ReportServer/ReportExecution2005.asmx";
string historyID = null;
string deviceInfo = null;
string format = "PDF";
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
rs2005Execution.Warning[] warnings = null;
string[] streamIDs = null;
string fileName = @"c:\samplereport.pdf";
string _reportName = @"/My Reports/<reportname>";
string _historyID = null;
bool _forRendering = false;
rs2005.ParameterValue[] _values = null;
rs2005.DataSourceCredentials[] _credentials = null;
rs2005.ReportParameter[] _parameters = null;
try
{
_parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
rs2005Execution.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);
rs2005Execution.ParameterValue[] parameters = new rs2005Execution.ParameterValue[1];
if (_parameters.Length > 0)
{
parameters[0] = new rs2005Execution.ParameterValue();
parameters[0].Label = "<replace with="" parameter="" label="">";
parameters[0].Name = "<replace with="" parameter="" name="">";
parameters[0].Value = "<replace with="" parameter="" value="">";
}
rsExec.SetExecutionParameters(parameters, "en-us");
results = rsExec.Render(format, deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
using (FileStream stream = File.OpenWrite(fileName))
{
stream.Write(results, 0, results.Length);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
</replace></replace></replace></reportname></servername></servername>
|
|
|
|
|
actually this is even easier. You have far too much code and this guy made things confusing without saying where to grab info
<br />
string deviceInfo = null;<br />
string extension = String.Empty;<br />
string mimeType = String.Empty;<br />
string encoding = String.Empty;<br />
Warning[] warnings = null;<br />
string[] streamIDs = null;<br />
string historyId = null;<br />
<br />
ReportExecutionService rsExec = new ReportExecutionService();<br />
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;<br />
rsExec.Url = ConfigurationManager.AppSettings["ReportServer"] + "/ReportExecution2005.asmx";<br />
rsExec.LoadReport("/ReportMainFolder/ReportName", historyId);<br />
<br />
rsExec.SetExecutionParameters(<br />
new ParameterValue[]<br />
{new ParameterValue() {Name = "ParamEvent", Value = "MyValue"}},null);<br />
<br />
Byte[] results = rsExec.Render("PDF", deviceInfo,<br />
out extension, out encoding,<br />
out mimeType, out warnings, out streamIDs);<br />
<br />
Walla...almost no code, it's easy to manage and your done.
Take the bytes and add as an attachment to mail:
<br />
mailMessage.Attachments.Add(new Attachment(new MemoryStream(attachment),String.Format("{0}_DocumentSavingsReport.pdf", "ReportName") ));<br />
or
<br />
Response.Write(result);<br />
It's just that easy folks!
l8rs
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Hi
I have created the PDF file successfully. but i need to protect my pdf file by using the password.. Is is possible ?.. if any one know kindly help me..
Thanks and Regards
Selvaraj
|
|
|
|
|
Hi,
I protected the pdf using ISharpText Liabrary, its open source liabray.
check the below code.
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Dim password As String = "yourPassword"
Dim outputFile As String = "c:\myPasswordPdf.pdf"
Dim reader As PdfReader = New PdfReader("PathForPdf")
PdfEncryptor.Encrypt(reader, New IO.FileStream(outputFile, FileMode.Create), True, password, password, PdfWriter.ALLOW_PRINTING)
|
|
|
|
|
I have a couple of reports about 30 pages long mixed with graphs, matrixes and tables.
I access these reports using an url. When rendering to html it takes about 30 seconds, and when rendering to pdf it takes about 90 seconds. These reports has been converted from crystal reports, crystal manages to render the same report to pdf in 30 seconds.
Is there anything I can do to improve rendering performance (to pdf)?
regards
Richard
|
|
|
|
|
Sorry I looked at this and it didn't work and looks like rubbish, I have made a far simpler version here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReportExecutionServiceReference;
namespace Reporting
{
public class ReportPDFTools
{
public byte[] RenderPDFReport( string url, string reportPath, ReportParameter[] parameters )
{
ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string format = "PDF";
string historyID = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
execInfo = rs.LoadReport(reportPath, historyID);
rs.SetExecutionParameters(
parameters.Select(
p => new ParameterValue
{ Label = p.Name,
Name = p.Name,
Value = p.Value }
).ToArray(), "en-us");
rs.ExecutionHeaderValue = execHeader;
rs.ExecutionHeaderValue.ExecutionID = execInfo.ExecutionID;
return rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
}
}
public struct ReportParameter {
public string Name;
public string Value;
}
}
You can then drive this from a simple console application method, this is what I did:
///
/// -p, --renderpdf-report <reportserviceurl> <reportpath> <outputfile> <param />[..]
///
/// <param name="args" />
private static void RenderPDFReport(string[] args)
{
if (args.Contains("-p") || args.Contains("--renderpdf-report"))
{
if( args.Where( s => !s.Contains("=") ).Count() != 4 )
throw new ArgumentException( "Expected 4 non-param arguments, failing." );
Console.WriteLine("Rendering PDF Report...");
ReportPDFTools pdfTools = new ReportPDFTools();
ReportParameter[] _params =
args.Where(
s => s.Contains("=") )
.Select(
s => new ReportParameter{
Name=s.Split('=')[0],
Value=s.Split('=')[1] }
).ToArray();
File.WriteAllBytes(args[3],
pdfTools.RenderPDFReport(args[1], args[2], _params)
);
}
}
Regards
Tim Scarfe (www.developer-x.com)
|
|
|
|
|
We are losing all our nice white space formatting here!
I uploaded the bits to http://www.developer-x.com/dropbox/ReportingServices/RenderPDFReport.txt
Have fun
Tim Scarfe
|
|
|
|
|
|
i have also the problem when exporting to pdf, i get blank pages in the middle of the report.
i have a report that generates data grouped by territory, and each group has a different size.
so if u try to put 10 lines of data by page, it can't work, i get blank pages anyway.
|
|
|
|
|
Hi,
I have Deployed reports in my Report Server.
All the reports are working fine,
Then i send mail from particular user,
so try to create a new subscription,
but error thrown...
"The current action cannot be completed because the user data source credentials that are required to execute this report are not stored in the report server database. (rsInvalidDataSourceCredentialSetting) Get Online Help"
in my project folder am used two rdl files
example for (Report1.rdl, Report2.rdl)
& two Data Source (Remote1.rds, Remote2.rds)
Report1.rdl file is point to one Remote Machine using Remote1.rds datasource, Report2.rdl file is point to another Remote Machine using Remote2.rds datasource
its properly running in my ReportServer area
but create new subscription area thrown an error..
anybody give idea for that issue..
thanks for advance
regards,
Ram...
|
|
|
|
|
Can any body explain why I am getting blank pages when I export the report in pdf format?
Thank you.
vedd
|
|
|
|
|
I have a report which contains so many components.Some of these components are having the Visibility conditions.The Problem is that I am getting large white spaces between components while exporting the report to PDF.How can I avoid getting these spaces in PDF?
|
|
|
|
|
I have the same problem. Really annoying.
Some spaces i could avoid because there were overlapping items. but now there are no overlapping items. argh...
I'm using a list in a list. Both lists contain some textboxes. thats all.
Please help
|
|
|
|
|
I have managed to sort out the code above and get the application compiling and executing. However there seems to be a problem with the parameter that I define and and set with the SetExecutionParameters() method.
Everytime I try to run my report the following error is displayed
This report requires a default or user-defined value for the report
parameter 'contractid'. To run or subscribe to this report, you must provide a parameter value.
I am setting this parameter as follows:
parameters[0] = new ParameterValue();
parameters[0].Name = "contractid";
parameters[0].Value = "1";
rs.SetExecutionParameters(parameters, "en-us");
where rs is an ExecutionService.
If anyone knows what I am doing wrong or what I need to change on my report to get this working I'd like to hear from you.
mtembene
|
|
|
|
|
OK I figured it out after a bit of hacking.
In the end I discovered that though the parameter I had to set was a string the report writer and a set of predefined valid parameter values that had to be met. That was my first problem.
When running the report manually I could pick the parameter I wanted from a drop down list. The drop downlist actually provided a Guid as a parameter to the report.
So in the end I had to create a Guid in my code. Assign it a valid value and then add that value as a string to the parameter for my report.
Obvious in the end.
|
|
|
|
|
Hi - I have exactly the same problem with drop-down choices in a report, but dont quite understand what you mean
when you mention the use of a GUID. Do you mean that each option in the dropdown has an associated GUID that is the real value of the parameter - if so how do you get these values. Hope to hear from you soon.
Scott Hayles (scott.hayles@ntsolutions.com.au)
|
|
|
|
|
Hi All, I am having trouble getting this running - does anybody have a sample of this in a VS solution that I could have a look at please?
Sorry for being dense... All help greatfully received...
:-/
|
|
|
|
|
Hi - with help I think I am making progress...
I am running into a problem very similar to the thread below this:
The report on my SSRS instance is stored in Home > Pauls Case Report > Report1
So I assume the path for the reportname variable should be "/Pauls Case Report/Report1" However - this returns me back a 404 error (not found)...
I can see it's the rs.getparameters block thats throwing this...
Any idea's?
Brgds, Paul.
|
|
|
|
|
A sample for VS development is as :-
ReportService2005.CatalogItem myCatalog=new TestApp.ReportService2005.CatalogItem();
ExecutionHeader header=new ExecutionHeader();
ExecutionInfo rpt = myReportExec.LoadReport("/Report Project/Report1", null);
myReportExec.ExecutionHeaderValue = header;
myReportExec.ExecutionHeaderValue.ExecutionID = rpt.ExecutionID;
--------To load a report------.
Hope this helps bcoz ur problem is for loading only.
|
|
|
|
|
Hi - thanks for getting back to me so quickly - I really appreciate this.
So,
I declare as follows:
private ReportService2005.ReportingService2005 rs;
private ReportExecution2005.ReportExecutionService rsExec;
then...
// Create a new proxy to the web service
rs = new ReportService2005.ReportingService2005();
rsExec = new ReportExecution2005.ReportExecutionService();
// Authenticate to the Web service using Windows credentials
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Assign the URL of the Web service
rs.Url = "http://anitemscrm/ReportServer" + "$REPORTSERVER2005/ReportService2005.asmx";
rsExec.Url = "http://anitemscrm/ReportServer" + "$REPORTSERVER2005/ReportExecution2005.asmx";
ReportService2005.CatalogItem myCatalog = new ReportService2005.CatalogItem();
ReportExecution2005.ExecutionHeader header = new ReportExecution2005.ExecutionHeader();
ReportExecution2005.ExecutionInfo rpt = rsExec.LoadReport("/Pauls Case Report/Report1", null);
rsExec.ExecutionHeaderValue = header;
rsExec.ExecutionHeaderValue.ExecutionID = rpt.ExecutionID;
However - I still get back error 404 not found...
Brgds, Paul.
|
|
|
|
|
All sorted now - thank you very much for your help and for an excellent source of information
Paul...
|
|
|
|
|
Hi Paul,
How did you solved it? I have exactly the same problem .
Any help is appreciated!
|
|
|
|
|
FYI ~
For those you have the same problem, here is how I fixed mine:
Replace
rs.Url = "http://SQL1/ReportServer" +
"$REPORTSERVER2005/ReportService2005.asmx";
rx.Url = "http://SQL1/ReportServer" +
"$REPORTSERVER2005/ReportExecution2005.asmx";
With
rs.Url = "http://SQL1/ReportServer" + "/ReportService2005.asmx";
rx.Url = "http://SQL1/ReportServer" + "/ReportExecution2005.asmx";
Hope this help!
|
|
|
|