Sunday 17 February 2013

ADO .NET Basics


Ado.net is set of libraries that allow interacting with database. There are many different types of data base available. For Ex, Microsoft SQL Server, Microsoft Access, Oracle, Borland Interbase and IBM DB2.

ADO.Net Flow:
                     

ADO.NET Data Providers are class libraries that allow a common way to interact with specific data sources.
Provider Name
API prefix
Data Source Description
ODBC Data Provider
Odbc
Data Sources with an ODBC interface. Normally older data bases.
OleDb Data Provider
OleDb
Data Sources that expose an OleDb interface, i.e. Access or Excel.
Oracle Data Provider
Oracle
For Oracle Databases.
SQL Data Provider
Sql
For interacting with Microsoft SQL Server.
Borland Data Provider
Bdp
Generic access to many databases such as Interbase, SQL Server, IBM DB2, and Oracle.

ADO.Net Objects:
                                  Ado.Net Provide many object to interact with data, I will explain some primary object we will be use. The objects below are the ones you must know.

·         SqlConnection Object
·         SqlCommand Object
·         SqlDataReader Object
·         SqlDataAdapder Object
·         Dataset object

SqlConnection Object:
                             The connection object is helps to identify the database server, the database name, user name, password, and other parameters that are required for connecting to the data base. A connection object is used by command objects so they will know which database to execute the command on.
SqlCommand Object:
                           The Command object to specified Action occur your database. You can use Sql statement for a database. A command object uses connection object figure out the specified connection or we can uses alone. The command object can execute directly or assign reference to SqlAdapder.
SqlDataReader Object:
                                       Some of operation needs to get only a stream data for reading. The Data reader object allow to obtain the result SELECT Statement to execute command object. For performance reason. The data returned from a data reader is a fast forward-only stream of data. This means that you can only pull the data from the stream in a sequential manner this is good for speed.
SqlDataAdapder object:  
                                         Some time we work with data primarily read-only and you rarely need to make changes. The data adapter makes it easy for you to accomplish these things by helping to manage data in a disconnected mode. The data adapter fills a Dataset object when reading the data and writes in a single batch when persisting changes back to the database. A data adapter contains a reference to the connection object and opens and closes the connection automatically when reading from or writing to the database. Additionally, the data adapter contains command object references for SELECT, INSERT, UPDATE, and DELETE operations on the data.    
DataSet Object:
                             Dataset objects are in-memory representations of data. They contain multiple Data table objects, which contain columns and rows, just like normal database tables. You can even define relations between tables to create parent-child relationships. The Dataset is specifically designed to help manage data in memory and to support disconnected operations on data, when such a scenario make sense. The Dataset is an object that is used by all of the Data Providers, which is why it does not have a Data Provider specific prefix.                                          

Sunday 3 February 2013

Improve Performance of ASP.Net Web Application


Improved Performance for ASP.Net Web Application


                              See! Most web application or web site is loading very slowly and each every action does not well. It’s happening is based on ugly coding and some unwanted things are using,

This is one of the performance issues, we should check and use needed properties of asp.net application, the following lists to be improve the Performance of web application in Asp.net 

  • Turn off Session State, if not required
  • Disable View State of a Page if possible
  • Set debug=false in web.config
  • Avoid Response.Redirect
  • Unnecessary round trips
  •  Use Finally method to kill resources
  •  Use Client Side Scripts for validations
  • Avoid unnecessary round trips to the server
  • Use Page.ISPostBack
  • Include Return statements with in the function/method
  • Use Foreach loop instead of For loop for String Iteration
  • Always check Page.IsValid when using Validator Controls
  • Store your content by using caching
  • Use minimize the number of web server controls

Understand the basic Coding Standard in C#


                                    Coding Standard in C#

Anyone can write a code. With a few months of programming experience, you can write 'working applications'. Making it work is easy, but doing it the right way requires more work, than just making it work.

         Everybody say some different definition for good code, in my definition is following point for good code.

·         Reliable
·         Maintainable
·         Reusable
 
Most of the developers writing code for higher performance, compromising reliability and maintainability. Efficiency and performance comes below reliability and maintainability. If your code is not reliable and maintainable, you can spend lot of time to finding the issues and you can’t give a proper fix.

       Any other developer to work your code or fix any issues he can understand the code what did, use proper commands and signatures, when a good developer is doing like this comes below of reusability of standards.

Note :
The terms Pascal Casing and Camel Casing are used throughout this document.
Pascal Casing - First character of all words are Upper Case and other characters are lower case.
Example: BackColor
Camel Casing - First character of all words, except the first word are Upper Case and other characters are lower case.
Example: backColor


1.     Use Pascal casing for Method names

Private void SayHello(string name)
{
       ...
}


2.     Use Camel casing for variables and method parameters

int totalCount = 0;
Private void SayHello(string name)
{
       string fullMessage = "Hello " + name;
       ...
}

3.     Use the prefix “I” with Camel Casing for interfaces ( Example: IEntity )

4.     Do not use Hungarian notation to name variables.

In earlier days most of the programmers liked it - having the data type as a prefix for the variable name and using m_ as prefix for member variables. Eg:

string m_sName;
int nAge;

However, in .NET coding standards, this is not recommended. Usage of data type and m_ to represent member variables should not be used. All variables should use camel casing.

5.     Use Meaningful, descriptive words to name variables. Do not use abbreviations.

Good:

string address
int salary

Not Good:

string nam
string addr
int sal

6.     Do not use single character variable names like i, n, s etc. Use names like index, temp

One exception in this case would be variables used for iterations in loops:

for ( int i = 0; i < count; i++ )
{
       ...
}

If the variable is used only as a counter for iteration and is not used anywhere else in the loop, many people still like to use a single char variable (i) instead of inventing a different suitable name.

7.     Do not use underscores (_) for local variable names.

8.     All member variables must be prefixed with underscore (_) so that they can be identified from other local variables.

9.     Do not use variable names that resemble keywords.

10.  Comments should be in the same level as the code (use the same level of indentation).
        Good:
// Format a message and display

11.   The curly braces should be on a separate line and not in the same line as if, for etc.

Good:
              if ( ... )   
              {
                     // Do something
              }

Not Good:

              if ( ... )    {
                     // Do something
              }



12.  Use #region to group related pieces of code together. If you use proper grouping using #region, the page should like this when all definitions are collapsed