Monday, April 28, 2008

Bind Data with dataset

SqlConnection con=new SqlConnection("user id=sa;password=;database=northwind;data source=compaq12");
SqlDataAdapter da=new SqlDataAdapter("select * from orders order by "+ str,con);
DataSet ds=new DataSet();

Bind data with datareader

void Page_Load(Object sender, EventArgs e)
SqlConnection myConnection;
SqlCommand myCommand;
SqlDataReader myDataReader;
myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); myConnection.Open();
//prepare sql statements

myCommand = new SqlCommand("SELECT TOP 10 * FROM EMPLOYEE", myConnection);
myDataReader = myCommand.ExecuteReader();
while (myDataReader.Read())
Response.Write(" ");
Response.Write(" ");
//New Line

//cleanup objects


1) Return Multiple Resultsets
2) Connection Pooling and Object Pooling
3) Use SqlDataReader Instead of Dataset wherever it is possible
4) Keep Your Datasets Lean
5) Avoid Inefficient queries
6) Unnecessary round trips
7) Too many open connections
8) Avoid Transaction misuse
9) Avoid Over Normalized tables
10) Reduce Serialization
11) Do Not Use CommandBuilder at Run Time
12) Use Stored Procedures Whenever Possible
13) Avoid Auto-Generated Commands
14) Use Sequential Access as Often as Possible

Asp.Net Web applications Performance tuning

1) Turn off Tracing unless until required
trace enabled="false"
2) Turn off Session State, if not required
<@%Page EnableSessionState="false"%>
3) Disable View State of a Page if possible
4) Set debug=false in web.config
5) Avoid Response.Redirect
5. A) To reduce CLR Exceptions count, Use Response.Redirect (".aspx", false) instead of response.redirect (".aspx").
6) Use the String builder to concatenate string
7) Avoid throwing exceptions
8) Use Finally Method to kill resources
9) Use Client Side Scripts for validations
10) Avoid unnecessary round trips to the server
11) Use Page.ISPostBack
12) Include Return Statements with in the Function/Method
13) Use Foreach loop instead of For loop for String Iteration
14) Avoid Unnecessary Indirection
15) Use "ArrayLists" in place of arrays
16) Always check Page.IsValid when using Validator Controls
17) Use Paging
18) Store your content by using caching
19) Use low cost authentication
20) Minimize the number of web server controls
21) Avoid using unmanaged code
22) Avoid making frequent calls across processes
23) Cleaning Up Style Sheets and Script Files
24) Design with ValueTypes
25) Minimize assemblies
26) Encode Using ASCII When You Don't Need UTF
27) Avoid Recursive Functions / Nested Loops
28) Minimize the Use of Format ()
29) Place StyleSheets into the Header
30) Put Scripts to the end of Document
31) Make JavaScript and CSS External