Wednesday, September 26, 2012

What is Assembly and what is the different type of assemblies .Net?

1 comments Posted by Rahul Kharde at 8:19 AM

An assembly may be Public or Private. A public assembly is also called a Shared Assembly.” 

  • The .NET assembly is the standard for components developed with the Microsoft.NET. 
  • Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file.
  • All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.
Advantages of Assemblies
  1. In the case of DLLs if a DLL has to be shared with some other application, it has to be registered in that particular machine. But, In the case of Asp.net assemblies there is no such type of registration required. Here we just need to do is to copy the assembly and put in the bin directory of the application that is going to use it.
  2. If we need to share a particular assembly with any other applications. we can do so by placing the assembly in the Global Assembly Cache (GAC). But before we going to do it we need to give a strong name to that assembly.Strong name is similar to GUID(It is supposed to be unique in space and time) in COM, components.Strong Name is only needed when we need to deploy assembly in Global Assembly Cache (GAC).Strong Names helps GAC to differentiate between two versions.Strong names use public key cryptography (PKC) to ensure that no one can spoof it.PKC use public key and private key concept.
  3. Another advantage of using ASP.Net assemblies is the ability to read the contents of an assembly. Each assembly has a manifest that has details about the assembly itself.
  4. The System.Reflection namespace has classes like Assembly which can be used to get the details of the assembly and with that it is also possible to load an assembly dynamically at runtime.

There are three types of assemblies in .NET
  • Private Assemblies
  • Public/Shared Assemblies.
  • Satellite Assembly
Private Assemblies

Is the assembly which is used by application only, normally it resides in your application folder directory.

There is no version constraint in private assembly.


If an assembly is copied in to the respective application in which we would like to use is known as local assembly. if any changes made to the copy that will not reflect the copies in other applications.


 Public Assemblies

  • It resides in GAC, so that anyone can use this assembly. Public assemblies are always share the common.
  • It has version constraint.
  • This public assembly is stored inside the global assembly cache or GAC.GAC contains a collection of shared assemblies.
  • If an assembly is copied into the global place and reference is used from all other applications then this is called public or global assembly..if we want to copy assembly in global place we have to create strong name by using sn.exe.
Satellite Assembly

Satellite assemblies are used to build multi-linguistic applications. Application which has built in supportive of more than one human readable language is known as multi-linguistic applications.
  • Satellite Assemblies doesn’t contain any Data
  • Satellite assembly is containing cultural information.
  • Satellite assembly mainly used for to display information based on the Cultural setting of browser or region.

Suppose you developed your application in an English (en-US) locale. Now, your application has multilingual support. When you deploy your code in different location, for example in India, you want to show text, label messages in the national language (local language) which is other than English.

Satellite assemblies give this flexibility. You create any simple text file with translated strings, create resources, and put them into the bin\debug folder. That's it. The next time, your code will read the CurrentCulture property of the current thread and accordingly load the appropriate resource.
Please refer below URL for Satellite Assembly


Read More »

Tuesday, September 18, 2012

Difference between Dataset and DataReader

0 comments Posted by Rahul Kharde at 9:48 PM

DataSet object

DataReader object

It is defined with multiple tables.

It is a read only and forward only data.

It is a disconnected architecture

It is comes under connected architecture.

Read/Write access

Read-only access

Bind to multiple controls

Bind to a single control

Slower access to data

Faster access to data

Dataset is non persistence.

DataReader is persistence.

Read More »

Monday, September 17, 2012

What is Cursor with examples in SQL Server 2008?

0 comments Posted by Rahul Kharde at 10:44 PM


What is cursor?

A cursor can be viewed as a pointer to one row in a set of rows. The cursor can only reference one row at a time, but can move to other rows of the result set as needed.

To use cursors in SQL procedures, you need to do the following:

  1. Declare a cursor that defines a result set.
  2. Open the cursor to establish the result set.
  3. Fetch the data into local variables as needed from the cursor, one row at a time.
  4. Close the cursor when done

To work with cursors you must use the following SQL statements:

  • DECLARE CURSOR
  • OPEN CURSOR
  • FETCH ROW By ROW
  • CLOSE CURSOR

Example

Create the table of Employee

CREATE TABLE Employee

(

EID INT PRIMARY KEY IDENTITY,

ENAME VARCHAR(50),

SALARY DECIMAL(10,2),

DEPT VARCHAR(50)

)

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('ABC',2000.00,'HR')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('XYZ',4000.00,'SUPPORT')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('DEF',6000.00,'SUPPORT')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('PQR',1000.00,'HR')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('MNL',7000.00,'MARKETING')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('OPQ',6000.00,'HR')

INSERT INTO Employee(ENAME,SALARY,DEPT)VALUES('RST',9000.00,'ACCOUNT')

SELECT * FROM Employee

Now we are updating salary 20% row by row

DECLARE @EID VARCHAR(50)

DECLARE db_cursor CURSOR FOR

SELECT EID FROM Employee

OPEN db_cursor

FETCH NEXT FROM db_cursor INTO @EID

WHILE @@FETCH_STATUS = 0

BEGIN

UPDATE Employee SET SALARY=SALARY+(SALARY*0.20)

WHERE EID=@EID

FETCH NEXT FROM db_cursor INTO @EID

END

CLOSE db_cursor

DEALLOCATE db_cursor

Result


Read More »

Thursday, September 13, 2012

Check Constraint in SQL-Server

0 comments Posted by Rahul Kharde at 11:45 PM

A check constraint is a rule that identifies acceptable column values for data in a row within a SQL Server table. The CHECK constraint ensures that all values in a column satisfy certain conditions.

Example

We will create an Employee table with Check constraint,

Employee Table contain Employee ID, Name and Age.

We set Check constraint property on Age column. Age should not be less than 18

Create table of Employee as follows.

CREATE TABLE Employee

(

EID INT PRIMARY KEY IDENTITY,

ENAME VARCHAR(100),

EAGE INT

CHECK (EAGE>18)

)

Try to insert the below records


INSERT INTO Employee(ENAME,EAGE)VALUES('ABC',20)


Check Constraint allowed to insert record in to the Employee table.but when we try to insert below record, it will shows an error Message


INSERT INTO Employee(ENAME,EAGE)VALUES('PQR',15)


Msg 547, Level 16, State 0, Line 1

The INSERT statement conflicted with the CHECK constraint "CK__Employee__EAGE__5AEE82B9". The conflict occurred in database "XXXX", table "dbo.Employee", column 'EAGE'.

The statement has been terminated.

Employee Contain only first record

SELECT * FROM Employee

Read More »

Thursday, September 06, 2012

Difference between Static Constructor and Private Constructor

1 comments Posted by Rahul Kharde at 4:53 AM

Static Constructor
Private Constructor
The static constructor will only be executed once.
The private constructor will be executed each time it is called.
The static constructor cannot have parameters.
The private Constructor may have parameters
A static constructor is called before the first instance is created. So it’s kind of global initialize.
Private constructor is called after the instance of the class is created. Inheritance-wise both are same.
A class can have only one static constructor
A class can have multiple private constructors
public static class Class1
{
   static Class1()
  {
   }
}
public class Class2
{
    private Class2()
   {
   }
}

Read More »
 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top