Runtime Debugger

March 19, 2008

how to improve Asp.Net application performance ?

Filed under: asp.net, code performance — Tags: , , — kannan Ambadi @ 11:29 am


I’ve found a very gud blog on how to improve Asp.Net application performance. The article reminds you some important tips that u usually forget at the time of coding. please have a look on this.
20 Tips to Improve ASP.net Application Performance

Kannan M ambadi

March 18, 2008

Heroes(Never) Happen Here………..!!!!!!!!

Filed under: microsoft, visual studio — kannan Ambadi @ 1:55 pm

Hi,

I got a chance to attend the Microsoft First Look Clinic event held at trivandrum on March 15th. I did the registration a week before and eagerly waited for the event. But what happened on the day is something that u would never expect from Redmondians. I’ve reached event center on time, waited around 45 mins. There were no sense of microsoft’s event goin on as people were moving as usual. Atlast, a lady came and confirmed our registration and later asked to sit in a computer lab, which has a seating capacity of 12-15. After 15mins, they slowly started the event by presenting a PPT(just reading the slides) by someone whom sitting somewhere in the building. We could hear only voice and ppt slides, no explanations, no doubts nothin.We felt like watching a comic show. As u know, 95% of .Net developers aware about visual studio 2008 and its features, then y did they gone for reading slides without any explanation ? they could have atleast show the demo of visual studio 2008. Did anyone expect such a poor show from world’s biggest software compnay, even google wont expect..sure…anyways leave it for the sake of At the end of the SHOW, they apologised for unavailabilty of the technical expert since they’ve got the information about the event TWO DAYS BACK..so they couldnt prepare well bla bla bla…. I was wondering why microsoft gone for such a flop marketing strategy for their MOST IMPORTANT products. It seems like microsoft promoting Heroes Never Happen Here.I took the videos of the fun movie (sorry event!!)  n u can see it from here 

Video: Heroes Happen Here!!!!!!!!

Kannan M ambadi

March 12, 2008

ORM Technology

Filed under: Ado.Net, LINQ, ORM Technology, asp.net, nHIbernate — Tags: , , , , , , , , — kannan Ambadi @ 3:12 pm

Hi, Last week i’ve attended a microsoft seminar on Visual Studio 2008 & VSTS. It was a nice presentation and we have had a delicious lunch too;)…Presentation on VSTS was amazing. The presenter, Tejsvi Kumar(Technology specialist from microsoft) , who provided clear idea on how we can handle a big project by Only using VSTS.Then he had shown demo on VSTS how Project manager can assign tasks, view status or create test cases on the fly etc. In between he also mentioned on visual studio 2008 features. i would to like express my appreciation to them for sharing their exp with us. And more than that, they’ve come up with more knowledge by replying our queries. Me too sent a mail regarding some queries on LINQ. I got a very detailed reply on this. I would like to share their reply with everyone since it provides a neat explaination on LINQ n other technologies.

Q : Can u differentiate between Ado.Net and LINQ
A : ADO.NET is a mechanism to connect to the data source (like ODBC) whereas LINQ is a query mechanism to query *any* kind of data not necessarily data from a database. As an example try the following simple LINQ program:

static void Main(string[] args)
{
int[] numbers = { 3, 5, 6, 1 };
var exp = from n in numbers
where n < 5
orderby n ascending
select n;
foreach(var e in exp )
{
Console.WriteLine(e);
}
}

This program demonstrates the following:

- LINQ is a language concept (integrating queries in the programming language)
- LINQ queries can be quite expressive including joins, where clauses, grouping etc.
- LINQ has nothing to do with databases in particular – however you can build LINQ based extensions that enable you to to query any kind of database using LINQ queries (e.g. LINQ to XML, LINQ to SQL, LINQ to datasets, LINQ to Entities, LINQ to Objects)

Q : Is LINQ is nothing but a copy if nHiberante ?
A : I disagree – LINQ is NOT copied from nHiberbate. The example in point 1 will explain that nHibernate has nothing similar. However you can definitely compare LINQ-to-SQL with nHibernate. Now nHibernate itself is no new technology – both nHibernate and LINQ-to-SQL are products that make use of the Object Relational Mapping (ORM) Technology. There are pro and cons of ORM technology and they are very widely discussed in the technology circles. You can get an insight into them on the net. The important thing to remember is that there are definitely some very important benefits (inspite of some disadvantages) of ORMs and if as an architect your analysis proves that ORM wil benefit your project you should go for it. Generally every technology has its pros and cons (like any other thing in life) and as a smart Architect you need to understand your requirements in nicely and then choose the technology that suits you best.

Q : LINQ(nHiberante) causes difficulty while debugging the code. Its very difficult to find which line throws exception.
A : This statement confirms my comment in point 3. Pro of LINQ-to-SQL(nHibernate) – faster code development; Con of LINQ-to-SQL (nHibernate) – possibly more extensive debugging. However, if you make you of some best practices for debugging you can reduce the time.

Q : Its very difficult to make changes according to Database changes..
A : Actually, with ORMs it becomes easier to abstract the Database changes from Application changes. So if your application is architected correctly and there are DB changes – with LINQ-to-SQL (or nHibernate) you will need to do NO or almost minimum changes in your code (all you have to do is change the mapping layer)

Q : Performance is slow compared to ado.Net(i’ve checked wit nHibernate, not wit LINQ)
A : Please read my blog post on performance generally: http://blogs.msdn.com/bsinghal/archive/2007/07/16/there-is-a-performance-problem.aspx.
To compare the performance of LINQ v/s non-LINQ scenario – you will need to do very thorough testing and make sure that we compare apples to apples.Regarding performance is slow with nHibernate or LINQ-to-SQL (ORMs) as compared to ADO.NET – yes that can be true in some cases even after doing all the possible optimizations etc because ORMs do add an extra layer of processing but they provide a lot of flexibility in return. The point here is that one should analyse the technology properly and make sure that any technology they choose addresses their requirements and needs. So if you are ready to spend 10 times more time in developing the application in ADO.NET at the cost of gaining lets say 2% performance improvement and of that is of more importance for your business then yes using ADO.NET is better.

Kannan M ambadi

March 11, 2008

Simple way to check your code performance

Filed under: asp.net, debug — Tags: , , , , , — kannan Ambadi @ 4:46 pm

Hi guys,

Of course, we all know foreach loop takes more time than for loop and there are lot of similar scenarios in .Net. Even if it takes lot of time, we’ll be forced to use foreach loop at some cases. So it’ll be better, if we come to know the time taken for executing a piece of code at the runtime. Here is a simple way to find out the time taken for each process.It just writes the start time and finish time taken for the process in the debug window. Debug.Indent() method simply changes the indentation of the Output by one level and Debug.WriteLine() method writes a string in the debug window.

Here is the snippet

//Increases the current IndentLevel
System.Diagnostics.Debug.Indent();
//Writes the starttime
System.Diagnostics.Debug.WriteLine(“DEBUG START TIME -> : ” + DateTime.Now.ToString(“HH:mm s:fff”));
//Execute the code
ConfigureControls();
//Writes the finish time
System.Diagnostics.Debug.WriteLine(“DEBUG FINISH TIME -> : ” + DateTime.Now.ToString(“HH:mm s:fff”));
//Reduces the current IndentLevel
System.Diagnostics.Debug.Unindent();

The result would be like this
debuug1.jpg

Kannan M ambadi

March 10, 2008

Exporting GridView as CSV

Filed under: GridView, asp.net — Tags: , , , , , , — kannan Ambadi @ 12:22 pm

Hi Everyone,

Below given an easy way to export data from gridview as CSV(comma seperated values) on a buttonclick. At first, it converts the datatable to html table format and then writes data as output stream. We need to set the Content-Type of Response object as Excel format and add the filename to be streamed on the client browser in a dialog box

Check this snippet

private void ExportToCsvFromDataSet(DataSet dsExport)
{
bool IsOutputStreamed = false;
try
{
StringBuilder dataToExport = new StringBuilder();
foreach (DataTable dtExport in dsExport.Tables)
{
string headerToExport= string.Empty;
foreach (DataColumn dCol in dtExport.Columns)
headerToExport = (char)34 + dCol.ColumnName + (char)34 + (char)44;
headerToExport.Remove(headerToExport.Length – 1, 1);
headerToExport = headerToExport + Environment.NewLine + Environment.NewLine;
dataToExport.Append(headerToExport);
string bodyToExport = string.Empty;
foreach (DataRow dRow in dtExport.Rows)
{
foreach (object obj in dRow.ItemArray)
bodyToExport = bodyToExport + obj.ToString() + (char)44;
bodyToExport.Remove(bodyToExport.Length – 1, 1);
bodyToExport = bodyToExport + Environment.NewLine;
}
dataToExport.Append(bodyToExport);
dataToExport.Append(Environment.NewLine);
dataToExport.Append(Environment.NewLine);
if (string.IsNullOrEmpty(dataToExport.ToString()))
{
Response.Clear();
Response.ContentType = “Text/vnd.ms-excel”;
Response.AddHeader(“Content-Disposition”, “attachment;filename=report.csv”);
Response.Write(dataToExport.ToString());
IsOutputStreamed = true;
}
}

}
catch { }
finally
{
if (IsOutputStreamed)
Response.End();
}

}

Download the source code

Kannan M ambadi

Blog at WordPress.com.