Sunday, September 9, 2012

Difference between Web Site and Web application in ASP.NET

• Development Wise Difference

Web Site
1. We can code one page in C# and one page in vb.net .
2. We cannot call (access) public functions from one page to other page.
3. Utility classes / functions must be placed in a special ASP.NET solder(the App_Code folder) 
4. Web Sites do not have a .csproj/.vbproj file that manages the project (the folder that contains the site becomes the project root). 
5. In the Web Site project, each file that you exclude is renamed with an exclude
keyword in the filename.
6. Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually.

Web Applications
1. Only one programming language allowed per project (Need to decide on programming language when starting project). 
2. We can access public functions from one page to other page.
3. Utility classes / function can be placed anywhere in the  Applications  folder structure. 
4. Web Applications are treated like other .NET Projects and are managed by a project file (.csproj or .vbproj) . 
5. One nice feature of the Web Application Project is it's much easier to exclude files from the project view.
6. Explicit namespaces are added to pages, controls, and classes by default.

• Deployment wise difference

Web Site
1. It has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime.
2. No need to recompile the site before deployment. 
3. We need to deploy both .aspx file and code behind file. 
4. Small changes to the site do not require a full re-deployment. (We can upload the code file that was changed) 

Web Application
1. web application is precompiled into one single DLL.
2. Site has to be pre-compiled before deployment .
3. Deploy only .aspx page, but not associated code file (the pre-compiled dll will be uploaded) .
4. Even small changes require a full re-compile of the entire site(i.e. if the code for a single page changes the whole site must be compiled) (It requires careful planning to ensure new bugs aren't introduced to the production site when uploading bug fixes or other changes.) 

Thursday, September 6, 2012

Difference between Primary Key and Foreign Key

primary key is a column which uniquely identifies the records in a table. In a broad sense, a primary key is the mixture of a unique key and an index: A collumn with a primary key is indexed to deliver a faster query, and doesn't allow duplicate values to ensure specific data.
Most programmers recommend all tables having a primary key (and only one) to enhance the speed of queries and overall database performance.
An example of a primary key may be found in a table named "departments," which might have a collumn named "department_number" that uniquely identifies each department in the table with a number.
foreign key is a column (the child column) in a table which has a corresponding relationship and a dependency on another column (the parent collumn) that is usually in a different table. Parent columns can have multiple child collumns, but a child collumn can only have one parent column.
The child collumn is the collumn with the foreign key; the parent collumn does not have the foreign key "set" on it, but most databases require the parent collumn to be indexed.
Foreign keys are made to link data across multiple tables. A child collumn cannot have a record that its parent collumn does not have.
Say a table named "employees" has 20 employees (rows) in it. There are 4 departments in the "departments" table. All 20 employees must belong to a department, so a collumn in the "employees" table named "department" would point to the primary key in the "departments" table using a foreign key. Now all employees must belong to a department as specified by the "departments" table. If a department isn't specified in the "departments" table, the employee cannot be assigned to it.

Difference between DDL, DML and DCL commands


DDL – Data Definition Language: statements used to define the database structure or schema. Some examples:
  • CREATE – to create objects in the database
  • ALTER – alters the structure of the database
  • DROP – delete objects from the database
  • TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT – add comments to the data dictionary
  • RENAME – rename an object
They are called Data Definition since they are used for defining the data. That is the structure of the data is known through these DDL commands.
DML – Data Manipulation Language: statements used for managing data within schema objects. Some examples:
  • SELECT – retrieve data from the a database
  • INSERT – insert data into a table
  • UPDATE – updates existing data within a table
  • DELETE – deletes all records from a table, the space for the records remain
  • MERGE – UPSERT operation (insert or update)
  • CALL – call a PL/SQL or Java subprogram
  • EXPLAIN PLAN – explain access path to data
  • LOCK TABLE – control concurrency
DML commands are used for data manipulation. Some of the DML commands
insert,select,update,delete etc. Even though select is not exactly a DML language command oracle still recommends you to consider SELECT as an DML command.
DML are not auto-commit. i.e. you can roll-back the operations, but DDL are auto-commit
DCL – Data Control Language. Some examples:
  • GRANT – gives user’s access privileges to database
  • REVOKE – withdraw access privileges given with the GRANT command
Data Control Language is used for the control of data. That is a user can access any data based on the priveleges given to him. This is done through DATA CONTROL
It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
TCL – Transaction Control: statements used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
  • COMMIT – save work done
  • SAVEPOINT – identify a point in a transaction to which you can later roll back
  • ROLLBACK – restore database to original since the last COMMIT
  • SET TRANSACTION – Change transaction options like isolation level and what rollback segment to use
For revoking the transactions and to make the data commit to the database we use TCL. 

Once we commit we cannot rollback. Once we rollback we cannot commit.
Commit and Rollback are generally used to commit or revoke the transactions that are with regard to DML commands.

Difference between Boxing And Unboxing


Tuesday, September 4, 2012

Difference between Public, Private, Protected .....


Public : Allows access to the class member from any other class.
Private : Allows access to the class member only in the same class.
Protected : Allows access to the class member only within the same class and from inherited classes.
Internal : Allows access to the class member only in the same assembly.
Protected internal : Allows access to the class member only within the same class, from inherited classes, and other classes in the same assembly.
Static : Indicates that the member can be called without first instantiating the class.

Difference between an Interface and an Abstract class


There are quite a big difference between an interface and an abstract class, even though both look similar.
    • Interface definition begins with a keyword interface so it is of type interface
    • Abstract classes are declared with the abstract keyword so it is of type class
    • Interface has no implementation, but they have to be implemented.
    • Abstract class’s methods can have implementations and they have to be extended.
    • Interfaces can only have method declaration (implicitly public and abstract) and fields (implicitly public static)
    • Abstract class’s methods can’t have implementation only when declared abstract.
    • Interface can inherit more than one interfaces
    • Abstract class can implement more than one interfaces, but can inherit only one class
    • Abstract class must override all abstract method and may override virtual methods
    • Interface can be used when the implementation is changing
    • Abstract class can be used to provide some default behavior for a base class.
    • Interface makes implementation interchangeable
    • Interface increase security by hiding the implementation
    • Abstract class can be used when implementing framework
    • Abstract classes are an excellent way to create planned inheritance hierarchies and also to use as non-leaf classes in class hierarchies. 

Difference between .EXE and .DLL files


EXE
  1. It is an executable file, which can be run independently.
  2. EXE is an out-process component, which means that it runs in a separate process.
  3. It cannot be reused in an application.
  4. It has a main function.

DLL
  1. It is Dynamic Link Library that is used as a part of EXE or other DLLs. It cannot be run independently.
  2. It runs in the application process memory, so it is called as in-process component.
  3. It can be reused in an application.
  4. It does not have a main function. 

Difference between Web.config and Machine.config


  • The settings made in the Web.config file are applied to that particular web application only whereas the settings of Machine.config file are applied to the whole asp.net application.
  • Web.config file Setting of asp.net all project Machine.config are setting of server setting and when the web side are implemented time it work all project but Web.config file set all projects
  • Web config will be for that particular aplln whereas the Machine .config will for the whole machine
  • Every ASP.NET application that you has a Web.config file . The settings specified in this will imply only to that application.Whereas Your System will have a Machine.config file in Microsoft.NET\Framework\v1.1.4322\CONFIG Folder which contains specifications and settings at a system level.
  • Web.config file is to override the settings from the Machine.config file. Machine.config file settings are applied to all the webapplications residing on the server while Web.config settings are application specific.
  • Machine. config is configuration file for all the application in the IIS. but Web.config is a configuration file for a application or folder.
  • Machine.config for machine level configuration. but Web.config for a application/folder level configuration

Friday, August 31, 2012

Difference between Data table Copy and the Clone method


Data table Copy and the Clone method:
"Both the Copy and the Clone methods create a new Data Table with the same structure as the original Data Table. The new Data Table created by the Copy method has the same set of Data Rows as the original table, but the new Data Table created by the Clone method does not contain any Data Rows."

In summary, Clone method creates a new Data Table with same structure and constraints but without data and Copy method does same but includes data too.

Copy 

datatable newTableCopy;
newTableCopy= existingTable.Copy();

datatable.copy : 
Creates a new datatable along with same structure - (schemas and constraints applied if any) including data in the existing table.

Clone

datatable newTableClone;
newTableClone= existingTable.Clone();.

datatable.Clone():

Creates a new datatable along with same structure with all schemas and constraints excluding data

Differences Between Authentication and Authorization


Authorization is process that comes after authentication and means that application is checking if user have rights to access to some part of web application. Very common example is administration area of site. Depending of user rights, application will allow or deny access to specific pages on site.

An authentication system is how you identify yourself to the computer. The goal behind an authentication system is to verify that the user is actually who they say they are. 
Authorization 
Once the system knows who the user is through authentication, authorization is how the system decides what the user can do. 


There are three major ways to authenticate and authorize users within an ASP.NET Web application:

(1) Windows integrated authentication.
      Identifies and authorizes users based on the server' s users list

(2) Forms authentication.  
     Directs users to a logon Web form that collects user name and password information, and    then authenticates the user against a user list or database that the application maintains.

(3) Passport authentication.
     Directs new users to a site hosted by Microsoft so that they can register a single user name and password that will authorize their access to multiple Web sites.

Wednesday, August 29, 2012

Difference between ASPX and ASCX

S.No
ASPX
ASCX
1
ASP.NET Page uses the extension .aspx
For eg: Default.aspx
User Control uses the extension .ascx
For eg: WebUserControl.ascx.
2
ASP.NET Page begin with a Page Directive.
For eg:
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default" %>

User Control begin with a Control Directive.
For eg:
<%@ Control Language="C#"
AutoEventWireup="true"
CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>

3
Usercontrol code can be used in webforms
We can not use webforms in usercontrol.

4
ASP.NET Page can be viewed directly in the Browser.

User Control cannot be viewed directly in the browser. User Controls are added to WebPages and we view them by requesting a web page in our browser
5
ASP.NET page has HTML, Body or Form element.
User Control does not have a HTML, Body or Form element.

Difference between IN and EXISTS


S.NoINEXISTS
1Returns true if specified value matches any value in the sub query or a list.Return true if sub query contain any rows.
2The sub query will run first and then only outer query.The Outer query will ran first and then only sub query.
3IN is slower than EXISTS. The IN is used in the widely For Static variables for eg: select name from table where ID in (Select ID from table2).Exists is faster than IN.The Outer query will run first and then only inner query.So it will reduce the over head. The Exists is useful mostly in IF conditional statements.
4
Example:

SELECT id,
[Name]
FROM dbo.tablea
WHERE id IN (SELECT id
FROM dbo.tableb)
Example:

SELECT id,
[Name]
FROM dbo.tablea AS a
WHERE EXISTS (SELECT id2
FROM dbo.tableb
WHERE id2 = a.id)

Difference between View and Stored Procedure


S.NoViewStored Procedure
1Does not accepts parametersAccept parameters
2Can be used as a building block in large query.Cannot be used as a building block in large query.
3Can contain only one single Select query.Can contain several statement like if, else, loop etc.
4Cannot perform modification to any table.Can perform modification to one or several tables.
5Can be used (sometimes) as the target for Insert, update, delete queries.Cannot be used as the target for Insert, update, delete queries.

Difference between for and foreach loop


S.NoFor loopForeach loop
1In case of for the variable of the loop is always be int only.In case of Foreach the variable of the loop while be same as the type of values under the array. 
2The For loop executes the statement or block of statements repeatedly until specified expression evaluates to false. The Foreach statement repeats a group of embedded statements for each element in an array  or an object collection. 
3There is need to specify the loop bounds(Minimum, Maximum). We do not need to specify the loop bounds minimum or maximum. 
4
example:  
using sytem;
  class class1
  {
      static void Main()
      {
         int j=0;
         for(int i=0; i<=10;i++)
          {
            j=j+1;
          }
           Console.ReadLine();
        }
      }  
example:  
using sytem;
  class class1
  {
     static void Main()
      {
        int j=0;
        int[] arr=new int[] {0,3,5,2,55,34,643,42,23};
        foreach(int i in arr)
        {
           j=j+1;
         }
         Console.ReadLine();
       }
  }  

Difference between ViewState and SessionState


S.NoViewStateSessionState
1
View state is maintained in page level only.
Session state is maintained in session level.
2
View state of one page is not visible in another page.i.e., when user requests another page previous page data will be no longer available.
Session state value is available in all pages within a user session.i.e., The data will be no longer available if user close the browser or session timeout occurs.
3
View state information stored in client only.
Session state information stored in server.
4
View state persist the values of particular page in the client (browser) when post back operation done.
Session state persist the data of particular user in the server. This data available till user close the browser or session time completes.
5
View state used to persist page-instance-specific data.
Session state used to persist the user-specific data on the server side.

Difference between Session and Cookies


S.NoSession StateCookies
1
Session can store any type of data because the value is of datatype of "object"
Cookies can store only "string" datatype
2
These are stored at Server side
They are stored at Client side
3
Session are secured because it is stored in binary format/encrypted form and it gets decrypted at server 
Cookie is non-secure since stored in text format at client side
4
Session is independent for every client i.e individual for every client
Cookies may or may not be individual for every client
5
There is no limitation on size or number of sessions to be used in an application
Due to cookies network traffic will increase.Size of cookie is limited to 40 and number of cookies to be used is restricted to 20.
6
For all conditions/situations we can use sessions
Only in few situations we can use cookies because of no security
7
We cannot disable the sessions.Sessions can be used without cookies also(by disabling cookies)
We can disable cookies
8
The disadvantage of session is that it is a burden/overhead on server
Since the value is string there is no security
9
Sessions are called as Non-Persistent cookies because its life time can be set manually
We have persistent and non-persistent cookies

Difference between Gridview,Datalist and Repeater


  • Gridview - Limited in design, works like an html table. More in built functionality like edit/update, page, sort. Lots of overhead.
  • DataGrid - Old version of the Gridview. A gridview is a super datagrid.
  • Datalist - more customisable version of the Gridview. Also has some overhead. More manual work as you have to design it yourself.
  • ListView - the new Datalist : Almost a hybrid of the datalist and gridview where you can use paging and build in Gridview like functionality, but have the freedom of design. One of the new controls in this family
  • Repeater - Very light weight. No built in functionality like Headers, Footers. Has the least overhead.
    Features of a GridView 
    •Displays data as a table
    •Control over
     –Alternate item
     –Header
     –Footer
     –Colors, font, borders, etc.
     –Paging
    •Updateable
    •Item as row
    Features of Repeater
    •List format
    •No default output
    •More control
    •More complexity
    •Item as row
    •Not updateable
    
    Features of DataList
    •Directional rendering
    •Good for columns
    •Item as cell
    •Alternate item
    •Updateable
    
     Repeater :
        It contains  Header Template, Item template , alternate
    Item template and footer template . it can't support
    Selection, editing, sorting and paging. this is read only
    and fast.
    
    Datalist :
     
       It contains Header Template, Item template , alternate
    Item template , Edit itm template and footer template . it
    can't support  sorting and paging but  support selection and
    editing
    
    DataGrid(or GridView) :
    
    It contains Header Template, Item template , alternate Item
    template , Edit itm template and footer template . it can
    support selection, editing , sorting and paging . Mostly
    every developer caught used this control  .

Monday, August 27, 2012

Difference between DataTable.Copy and DataTable.Clone


Both the methods DataTable.Clone and DataTable.Copyare are used to make copies of existing datatables, the difference is

DataTable.Clone() - Copies only the structure of the source table with the constraints, the data is not copied from the source table.

DataTable.Copy() - Copies the structure and data from the source table.


Example: 
DataTable.Clone()
DataTable dt;
dt= sourceTable.Clone();

Here, the targetTable is created with only the structure of the sourceTable
targetTable.Rows.Count() returns 0.

Example: DataTable.Copy()
DataTable dt;
dt= sourceTable.Copy();

Tuesday, August 21, 2012

Difference Between TRUNCATE & DELETE

TRUNCATE
DELETE
faster and uses fewer system and transaction log resources than DELETE.
 Slower than truncate because, it maintain logs for every record.
removes the data by deallocating the data pages used to store the tables data, and only the page deallocations are recorded in the transaction log.
removes  rows one at a time and records an entry in the transaction log for each deleted row.
removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column.
If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint;
use DELETE statement without a WHERE clause
Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
Activates Trigger
No Roll back
Can Rollback
DDL Command
DML Command

Difference between EXE and DLL

- EXE stands for Extensible Execute File and DLL stands for Dynamic Link Library. It is also called assembly in Dot Net.

- EXE gives direct output, it needs a resource and DLL does not give direct output, it always execute with any software and provide resource to that software.

- EXE is use by End User like-Client but DLL can not use by End User.

- An ActiveX Dll runs is an in process server running in the same memory space as the client process and an ActiveX Exe is an out of process server which runs in it's own separate memory space.

- EXE runs independently, whereas DLL runs within an EXE. DLL is an in-process file and EXE is an out-process file.

- A DLL would share the same process and memory space of the calling application while an EXE creates its separate process and memory space.

- And another difference is that EXEs are executable programs while DLLs are libraries loaded into a process and contain some sort of useful functionality like security, database access or something.

- EXE is mainly executable files which execute when user run the programs or click on them whereas DLL contains the function and procedure which link dynamically when needs them.

Difference between WCF and Web service


Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.

FeaturesWeb ServiceWCF
HostingIt can be hosted in IISIt can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming[WebService] attribute has to be added to the class[ServiceContraact] attribute has to be added to the class
Model[WebMethod] attribute represents the method exposed to client[OperationContract] attribute represents the method exposed to client
OperationOne-way, Request- Response are the different operations supported in web serviceOne-Way, Request-Response, Duplex are different type of operations supported in WCF
XMLSystem.Xml.serialization name space is used for serializationSystem.Runtime.Serialization namespace is used for serialization
EncodingXML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, CustomXML 1.0, MTOM, Binary, Custom
TransportsCan be accessed through HTTP, TCP, CustomCan be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
ProtocolsSecuritySecurity, Reliable messaging, Transactions

Features of WCF

  • Service Orientation
  • Interoperability
  • Multiple Message Patterns
  • Service Metadata
  • Data Contracts
  • Security
  • Multiple Transports and Encodings
  • Reliable and Queued Messages
  • Durable Messages
  • Transactions
  • AJAX and REST Support
  • Extensibility
WCF is a replacement for all earlier web service technologies from Microsoft. It also does a lot more than what is traditionally considered as "web services".