Saturday, July 26, 2014

.NET Framework


The .NET Framework defines an environment that supports the development and executionof highly distributed, component-based applications.The Microsoft .NET Framework is a software framework that can be installed on computers running Windows operating systems.
.NET Framework has 2 very important entities.

1)One is the Common Language Runtime (CLR).It manages the execution of your program. Along with other benefits, the Common Language Runtime is the part of the .NET Framework that enables programs to be portable. The CLR also provides other important services such as security, memory management, and exception handling. All .NET programs execute under the supervision of the CLR.

2) Other entity is .NET class library. This library gives your program access to the runtime environment. The .NET Framework includes a set of standard class libraries. The class library is organized in a hierarchy of namespaces. The .NET class libraries are available to all .NET languages. e.g. I/O Functionality, Database Connectivity API's When we compile a C# program, compiler produces pseudocode called Microsoft Intermediate Language (MSIL), intermediate code. MSIL is a set of portable instructions that are independent of any specific CPU. Then CLR translate the MSIL into executble code when program is run. These instructions i.e. MSIL is independent of any specific CPU. This is how .NET Framework achieves portabilty. CLR translate MSIL into exe using Just In Time (JIT) compiler. When a .NET program is executed, the CLR activates the JIT compiler. The JIT compiler converts MSIL into native code on demand basis.

One other thing which is output of compilation of a C# program, metadata.
Metadata describes the data used by your program and enables your code to
interact easily with other code. The metadata is contained in the same file as the MSIL
but developers can create their own metadata through custom attributes. Metadata contains information about the assembly.

There are two types of code i) Managed Code ii) Unmanaged Code
Managed code is executed under CLR. Unmanaged code is not executed under management of CLR. eg Pointers in c,c++.

Common Language Specification (CLS) :-
If you want your program to be used by other program written in different languages,
then your program should satisfy CLS. It includes Common Type System (CTS).
The Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented .
CTS enable cross-language integration & also defines the rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.


Functions of the Common Type System are :-
1) cross-language integration, type safety, and high performance code execution.
2) provides an object-oriented model that supports the complete implementation of many programming languages.
3) To ensure that objects written in different languages can interact with each other.



What’s New in Transact-SQL Server 2012

In April 2012, Microsoft announced the release of SQL Server 2012. 


So what’s new with T-SQL Server 2012?  Well, there are a lot of new features in the T-SQL Server 2012 editions. In this article we will discuss new features of T-SQL Server 2012.

  • Sequence :- It is a new construct to generate sequence numbers.  A sequence is a user-defined schema bound object that generates a sequence of numeric values according to the specification with which the sequence was created. Sequence can be ascending or descending and can be configured to restart when exhausted.  Future values can be cached by minimizing the disk IO.
  • Executing Stored Procedure with Result Sets :- It allows you to change the name and data type of columns in the results of the store procedure. Before SQL server 2012, we were doing the same but it was a lengthy procedure. First we had to create a temporary table and then execute the stored procedure and insert the result set in the temporary table and then select it.
                                                  
  • Offset and Fetch Clause :- It allows you to do server side paging. The OFFSET-FETCH clause provides you with an option to fetch only a window or page of results from the result set. OFFSET-FETCH can be used only with the ORDER BY clause.

  • THROW :-  Raises an exception and transfers execution to a CATCH block of a TRY…CATCH construct in SQL. It reduces the need of RAISERROR.

  • PARSE :- It attempts to parse string or convert it to specified data type. It can only convert to number or date time. It uses CLR for its operations. If a null constant is passed, an error is raised. A null value cannot be parsed into a different data type in a culturally aware manner If a parameter with a null value is passed at run time, then a null is returned, to avoid canceling the whole batch.

  • TRY_PARSE :- Returns the result of an expression, translated to the requested data type, or null if the cast fails in SQL Server 2012. Use TRY_PARSE only for converting from string to date/time and number types. This function depends on CLR.

  • TRY_CONVERT :- Returns a value cast to the specified data type if the cast succeeds; otherwise, returns null.

  • Logical IIF Function :-  Returns one of two values, depending on whether the Boolean expression evaluates to true or false in SQL Server 2012. IIF is a shorthand way for writing a CASE expression. It evaluates the Boolean expression passed as the first argument, and then returns either of the other two arguments based on the result of the evaluation. It has same limitations like CASE statement.

  • CHOOSE  :- It returns a value from specified list based on index.  If the index is not in list, it returns NULL value. It returns the data type based on data type precedence.
     
  • EOMONTH :- It returns the last date of specified month. You can optionally specify offset to increment or decrement result.

  •  CONCAT :- Returns a string that is the result of concatenating two or more string values. NULLS are automatically converted to empty strings. It can pass other data type for concatenations.
     
  • FORMAT :- It simplifies the string formatting of date or other data types. The functions returns string. It depends on CLR.