Tuesday, 16 June 2009

ASP .NET: Assigning Data to DataSet table

WebConfig

connectionStrings
add name="HRDWConnString" connectionString="Data Source=.;Initial Catalog='HR DW';Integrated Security=True" providerName="System.Data.SqlClient"/
/connectionStrings

Code

//Connect to DB
string connStr = ConfigurationManager.ConnectionStrings["YOURDBCONNECTION IN WEB CONFIG"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = @"SELECT
--[DisplayName]
[FileName]
,[ParameterName]
,[DefaultValue]
FROM [dbo].[vwLookupReportParameterDefaults]";
try
{
conn.Open();
SqlDataAdapter ad = new SqlDataAdapter(comm.CommandText.ToString(),conn);
ad.Fill(dataset, "Parameters");
Cache["dataset"] = ds;

//SqlDataReader dr = comm.ExecuteReader();
//while (dr.Read())
//{
//ReportParameters = new ListItem(dr[2].ToString(), dr[3].ToString());
//}
}
catch (Exception ex)
{
Response.Redirect("LoginError.aspx");
}
finally
{
conn.Dispose();
}


DataSet d = new DataSet();
d = (DataSet)Convert.ChangeType(Cache["dataset"], typeof(DataSet));
dt = d.Tables[0];
for (int i =0; i < dt.Rows.Count; i++) {
if (report == dt.Rows[i]["FileName"].ToString())
{
ReportParameter param = new ReportParameter(dt.Rows[i]["ParameterName"].ToString(), dt.Rows[i]["DefaultValue"].ToString());
ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { param });
}
}

ASP .NET: Caching values and Casting

Cache["dataset"] = Dataset; //Your Object

newDataset = (DataSet)Convert.ChangeType(Cache["dataset"], typeof(DataSet)); //Cast cached to newDataset

Details:
http://aspnet.4guysfromrolla.com/articles/022802-1.aspx

Monday, 15 June 2009

SSAS: Tips

http://www.obs3.com/as_tips.shtml

SSAS: Current Month in Cube

A named set which resolves the "current month" is very useful when building reports because the report can reference the named set rather than an individual month, which would need to be continually changed. Here is a piece of MDX code which returns the last month in the database which contains data.
Current Month = Tail( Filter( [Time].[Month].Members, Not IsEmpty([Time].CurrentMember)), 1)
Note: If you want to set the time dimension's "default member" to use the "current month" you will need to include .item(0) at the end of the statement to convert the set to an individual member.
The tips provided here have no implied warranty. They are provided as a free service and are informational in nature.

ASP .NET: User Authentication not going through to reports

Add:

authentication mode="Windows"/
identity impersonate="true"/

to web.config in System.Web

ASP .net: reportViewer Operation is not valid due to the current state of the object

While you are in a drillthrough report, the LocalReport object represents the drillthrough report - the value of the report path, parameters, etc. Conceptually, you can't change this report, it was defined by the parent report. If you could, it would leave the back button enabled on the toolbar, which doesn't really make sense. The correct thing to do is first call ReportViewer.Reset(). This will reset the report stacks and allow you to set a new definition.

ASP .NET: Update framework 2.0 to 3.5

Changes to the Default Web.config File in Visual Studio 2008As discussed in An Overview of ASP.NET 3.5 and Visual Studio 2008, Visual Studio 2008 can be used to create ASP.NET version 2.0, version 3.0, or version 3.5 applications. To specify the version being targeted, right-click on the website project in the Solution Explorer and select Property Pages from the context menu. From the Property Pages, select the Build option in the left column. You can then choose the version to target from the drop-down list on the right.

Visual Studio 2008 automatically updates the application's Web.config file based on the version being targeted.
Similarly, when you open an existing ASP.NET 2.0 application in Visual Studio 2008, you are prompted as to whether you want to upgrade the website to ASP.NET version 3.5.

Ref: http://www.4guysfromrolla.com/articles/121207-1.aspx