It is ASP.NET code in C#. Since you need to get the report in binary on
server side (reporting server), hence the ASP.NET.
save a report on the server side, you can call Reporting Services'
web services to generate the report, render it in desired format and save
it.
I just write a peice of code to allow user to request a report to be send to
a given email address as an attachment. Here is the simplified code (note,
you need to add web reference to the reporting services' web services):
private void GetReportByEmail()
{
//Validate txtEmail for inputting
if (txtEmail.Text.ToUpper().StartsWith("XX"))
{
lblPrompt.Text="You must enter a valid email address!";
lblPrompt.Visible=true;
return;
}
if (txtEmail.Text.IndexOf("@")<3) text="You must enter a valid email address!" visible="true;" rs="new" url="http://localhost/ReportServer/ReportService.asmx" credentials="System.Net.CredentialCache.DefaultCredentials;" report="/WDTimeSheets/TimeSheetEmp/PayrollSummary" historyid="null;" deviceinfo="null;" pmts="new" pmt="new" name="EmployeeID" value="lblEmpID.Text;" pmt="new" name="FromDate" value="DateTime.Parse(ddlFrom.SelectedValue).ToString(" pmt="new" name="ToDate" value="DateTime.Parse(txtTo.Text).ToString(" credentials="null;" showhide="null;" encoding="null;" mimetype="null;" pmtused="null;" warnings="null;" streamids="null;" reportdata="rs.Render(report," class="hilite4">PDF",historyID,deviceInfo,pmts,credentials,showHide,
out encoding,out mimetype,out pmtUsed,out warnings,out streamIDs);
}
catch(System.Web.Services.Protocols.SoapException ex)
{
lblPrompt.Text=ex.Message;
lblPrompt.Visible=true;
return;
}
//Save PDF report to a temp location
string
folder=System.Configuration.ConfigurationSettings.AppSettings["TempDataFolder"];
if (Directory.Exists(folder))
{
//Get a random file name
string f="PayRollSummary_" + DateTime.Today.ToString("yyyy-MM-dd") + "_"
+ lblEmpID.Text;
string fileName=folder + "\\" + f + ".pdf";
//Save the report (PDF) in a configured location
try
{
if (File.Exists(fileName)) File.Delete(fileName);
FileStream fs=File.OpenWrite(fileName);
fs.Write(reportData,0,reportData.Length);
fs.Close();
}
catch(System.IO.IOException ex)
{
lblPrompt.Text=ex.Message;
lblPrompt.Visible=true;
return;
}
//Send PDF file with email
EmailReport(fileName); //Method is omitted
}
else
{
lblPrompt.Text="Web server configuration error: emailing operation was
cancelled.";
lblPrompt.Visible=true;
}
}
Monday, November 23, 2009
Retreive current user permissions in SQL Server 2005
Retreive current user permissions in SQL Server 2005
If you want to retrieve the permissions available for the currently logged in user then you can use the function called fn_my_permissions in SQL Server 2005. Following are examples of its usage:
Use AdventureWorks
Go
—Return Caller’s permission on the current server
SELECT * FROM fn_my_permissions(NULL, ‘SERVER’);
Go
—Return Caller’s permission on the current database
SELECT * FROM fn_my_permissions(NULL, ‘DATABASE’);
Go
SELECT * FROM fn_my_permissions(‘Sales.vIndividualCustomer’, ‘OBJECT’);
Go
Subscribe to:
Posts (Atom)