Showing posts with label Reporting Service 2005. Show all posts
Showing posts with label Reporting Service 2005. Show all posts

Wednesday, April 28, 2010

Programmatically Generate Report and store as pdf or send as email

Every time going to Reporting service and generate report it's tedious work also some report takes longer with millions of data. User does not have time to click report generate button and wait for 10-15 minutes. Use need ready to use report with real time data. We can schedule service or Task and generate report in background and user get email on his/her schedule time. Here I tried to create some application and it's running very well on my production environment.
below if only basic structure of code.
1) Create New Windows / Web Application (depend on your requirment)
2) Add Web Refrence for Web Site / Service Refrence for Windows
http://SERVERNAME/ReportServer/ReportService2005.asmx
And
http://SERVERNAME/ReportServer/ReportExecution2005.asmx
3) If you are using .Net 3.5 can use WCF client, instead of web service client.
4) For excel, csv,web and xml --> try file extetion as .".xls",".csv",".html",".xml"


using System.Text;
using System.Windows.Forms;
using System.IO;

using System.Net.Mail;

private rs2005.ReportingService2005 rs;
private rsExecService.ReportExecutionService rsExec;


rs = new rs2005.ReportingService2005();
rsExec = new rsExecService.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://SERVERNAME/ReportServer/ReportService2005.asmx";
rsExec.Url = http://SERVERNAME/ReportServer/ReportExecution2005.asmx;

string historyID = null;
string deviceInfo = null;
string format = "pdf";

// Byte[] Sendresults;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
rsExecService.Warning[] warnings = null;
string[] streamIDs = null;
// Default Path;
string fileName = @"c:\samplereport.pdf";
// Get the report name
string _reportName = @"/FOLDER/REPORT_NAME";
string _historyID = null;
bool _forRendering = false;

ParameterValue[] _values = null;
DataSourceCredentials[] _credentials = null;
ReportParameter[] _parameters = null;
try
{
// Load the selected report.
rsExecService.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);

// Prepare report parameter.
rsExecService.ParameterValue[] parameters =
new rsExecService.ParameterValue[2];
// Place to include the parameter.
if (_parameters.Length > 0)
{
parameters[0] = new rsExecService.ParameterValue();
parameters[0].Label = "StartDate";
parameters[0].Name = "StartDate";
parameters[0].Value = DateTime.Now.Date.ToShortDateString();

parameters[1] = new rsExecService.ParameterValue();
parameters[1].Label = "EndDate";
parameters[1].Name = "EndDate";
parameters[1].Value = DateTime.Now.AddDays(1).ToShortDateString();
}
rsExec.SetExecutionParameters(parameters, "en-us");
//get pdf
byte[] Sendresults = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

MeoryStream ms = new MemoryStream(Sendresults);
//send email
MailMessage mail = new MailMessage();
mail.Subject = "Test_Report " + DateTime.Now.ToString();
mail.To.Add("eMailName@@XYZ.com");
mail.From = new MailAddress("DoNotReply@XYZ.com");
mail.Attachments.Add(new Attachment(ms, string.Format("{0}_Document." + format, "Test_Reprots")));
SmtpClient smtp = new SmtpClient("smtp.XYZ.net");
smtp.Send(mail);

// Create a file stream and write the report as file
using (System.IO.FileStream stream = File.OpenWrite(fileName))
{
stream.Write(Sendresults, 0, Sendresults.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/2c7d949b-5a3c-4443-b7f4-b20b4089d445

Monday, April 19, 2010

Login failed (rsLogonFailed)

when setup using execution account on reporting Service Configuration and allow Domain user access to reports. To solve issue remove Execution Account or Reset the Password.




Thursday, October 9, 2008

SQL Server Reporting Services 2005 "Error "




ERROR Message
====================================================================
An error has occurred because a control with id 'grdComplaints$ctl04$ctl00' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.

Fiest time report will display good.. but refresh/any post back event.. it throw error...

Try :
1) "EnableViewState" property of GridView was False. When I set it to True. still not works

2) Disable all State porpery to false - Still not work
3) Finally I tried from other browsers I works fine ... I still fining what different setting in my browser than others.

----or---

Change the security setting ...
Unchecked Anonymous user from IIS. Then you won't get any issue... but when you are using Anonymous user. you will get this error.. then follow as before.

Tuesday, July 22, 2008

Reporting Services 2005 Dynamic connection string

For report Shared data set use
="Data Source=" & Parameters!server.Value & ";Initial Catalog=" & Parameters!database.Value

For stand alone dataset
Data Source=PARAMETER!server.value;Initial Catalog=PARAMETER!database.value
Some Bugs in Reporting Service 2005
- Make Sure everytime you change anything or open report that Command type is Store procedure or Text . If you use Store procedure , It will change to text.
- If you use a Credential (User Id & password) even standard user ID & pass. when open reports from different user account It will go away. so, when you diploy report make sure Credential are there.