An Idea can change your life.....
Showing posts with label SQL Server Reporting Services. Show all posts
Showing posts with label SQL Server Reporting Services. Show all posts

Tuesday, September 16, 2008

SQL Server programming Group by day,Month ,Year

--group by day

SELECT COUNT(* ),

Dateadd(DAY,Datediff(DAY,0,HireDate),0) 'day'

FROM Employees

GROUP BY Dateadd(DAY,Datediff(DAY,0,HireDate),0)

ORDER BY Dateadd(DAY,Datediff(DAY,0,HireDate),0) DESC



--group by Month

SELECT COUNT(* ),

Dateadd(MONTH,Datediff(MONTH,0,HireDate),0) 'Month'

FROM Employees

GROUP BY Dateadd(MONTH,Datediff(MONTH,0,HireDate),0)

ORDER BY Dateadd(MONTH,Datediff(MONTH,0,HireDate),0) DESC



Monday, March 10, 2008

Executing client report from web application

protected void Page_Load(object sender, EventArgs e)
{
DataSet1TableAdapters.authorsTableAdapter ds = new DataSet1TableAdapters.authorsTableAdapter();
ds.ClearBeforeFill = true;
DataSet1.authorsDataTable dt=new DataSet1.authorsDataTable();
ds.Fill(dt, "ca");
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Pubs.rdlc");
ReportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WebForms.SubreportProcessingEventHandler(subReports);
}
void subReports(object sender, SubreportProcessingEventArgs e)
{
if (e.ReportPath.Equals("ClientSubReport"))
{
if (e.Parameters.Count > 0)
{
DataSet2TableAdapters.employeeTableAdapter da = new DataSet2TableAdapters.employeeTableAdapter();
da.ClearBeforeFill = true;
DataSet2.employeeDataTable dt = new DataSet2.employeeDataTable();
da.Fill(dt);
e.DataSources.Add(new ReportDataSource("DataSet2_employee",dt));

}
}
}

Wednesday, December 05, 2007

Visual Studio » Visual Studio Report Controls » ReportServerCredentials

The scenario is simple: I have a reportviewer control and want to show & print a ServerReport.

The application needs to be able to connect to the reporting service over the internet and the client machines do not need to be in the same domain.

This is the same authentication scenario that applies to viewing reports through HTTP using internet explorer and a URL to the reportserver virtual directory: Internet Explorer asks for a user and password.

Howerver, I want to specify the credentials programatically so the users don't need to enter them manually. Since the ReportViewer is connecting to the ReportServer website through HTTP (I guess its calling the webservice or even just displaying the HTML returned by the reportserver aspx), this should be pretty easy, just as its easy to setup a NetworkCredential(user, pass) for authentication when calling a webservice over http.

The solution follows





well , you should implement IReportServerCredential, and code example as follow :



public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{


// local variable for network credential.
private string _UserName;
private string _PassWord;
private string _DomainName;
public CustomReportCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}
public WindowsIdentity ImpersonationUser
{
get
{
return null; // not use ImpersonationUser
}
}
public ICredentials NetworkCredentials
{
get
{



// use NetworkCredentials
return new NetworkCredential(_UserName,_PassWord,_DomainName);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
{


// not use FormsCredentials unless you have implements a custom autentication.
authCookie = null;
user = password = authority = null;
return false;
}


}


then use this as follows:



IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

The other code to set ServerReport property omit. hope you have a good day.