Expert Dot Net

Trust me to find new way !

SQL Server 2016 new features

SQL Server 2016 is the biggest leap forward in Microsoft data platform history. There is a lot of buzz around SQL Server 2016. Gain real time insights across your transaction and analytical data with a salable database platform that has everything built in, from unparalleled in-memory performance, new security innovations and high availability, to advanced analytics that make mission-critical applications intelligent.

Always Encrypted -   SQL Server 2016 has introduced new feature that is Always Encrypted. If this feature is enabled in your SQL Server then all data would be in encrypted mode always. By this feature all the confidential data would be save and we can apply proper access control of data in proper mode.

Dynamic Data Masking - This is very interesting feature of SQL Server 2016 edition. If you want to hide some part of any data to be hidden by for some one and some part to be shown to some one then easily you can make this done using this feature. e.g. you have mobile number stored in database and you want to hide all digits except last 2 digits then easily you can perform this using Dynamic Data Masking feature.

JSON Support - JSON stands for Java Script Object Notation. Now using this feature of SQL Server 2016 you can easily interchange the data in JSON format.

TempDB Database Files -  During setup, you can configure the number of tempdb database files, initial size, auto growth and directory placement using the new UI input control on the Database Engine Configuration - TempDB section of SQL Server Installation Wizard.

Query Store - If you are into examining execution plans than you will like the new Query Store feature. Currently in versions of SQL Server prior to 2016 you can see existing execution plans by using dynamic management views (DMVs). But, the DMVs only allow you to see the plans that are actively in the plan cache. You can’t see any history for plans once they are rolled out of the plan cache. With the Query Store feature, This is a great addition and will allow you to now track execution plans performance for your queries over time. 

Row Level Security -  You can apply row level security in SQL Server 2016

 

C# For Loop

Loop is used in programming when you need to repeat any group of statement or statement more then one time. For loop is one important looping construct which is used to iterate set of instructions.


for ( int i=0 ; i <= 5 ; i++)

{

// Your statements

}


There are 4 parts of this for loop.


- First part is initialization

- Second part is condition checking

- Third part is increment / decrements

- Fourth part is group of statements which basically would be executed.


Demo 1 :




New Features introduces in .NET 4.5 and 5.0

C# evolution look in a glance : 


1. Parallel.ForEach

Parallel.ForEach is a feature introduced by the Task Parallel Library (TPL). This feature helps you run your loop in parallel. You need to have a multi-processor to use of this feature.

Simple foreach loop

foreach (string i in listStrings)
{
// put your statement here
}

Parallel foreach

Parallel.Foreach(listStrings, text=>
{
// put your statement here
});

2. BigInteger

BigInteger is added as a new feature in the System.Numerics DLL. It is an immutable type that represents a very large integer whose value has no upper or lower bounds.

BigInteger obj = new BigInteger("123456789123456789123456789");


3. ExpandoObject

The ExpandoObject is part of the Dynamic Language Runtime (DLR). One can add and remove members from this object at run time.

Create a dynamic instance.

dynamic Person = new ExpandoObject();
Person.ID = 1001;
Person.Name = "Princy";
Person.LastName = “Gupta”; 

4. Named and Optional Parameters

Optional Parameters

A developer can now have some optional parameters by providing default values for them. PFB how to create optional parameters.

Void PrintName(string a, string b, string c = “princy”)
{
     Console.Writeline(a, b, c)
}
We can now call the function PrinctName() by passing either two or three parameters as in the following:

PrintName(“Princy”,”Gupta”,”Jain”);
PrinctName(“Princy”,”Gupta”);

Output

PrincyGuptaJain
PrincyGuptaprincy

Note: An optional parameter can only be at the end of the parameter list.

Named Parameters

With this new feature the developer can pass values to parameters by referring to parameters by names.

Void PrintName(string A, string B
{
}
Function call

PrintName (B: “Gupta”, A: “Princy”);

With this feature we don't need to pass parameters in the same order to a function.

5. Tuple

A Tuple provides us the ability to store various types in a single object.

The following shows how to create a tuple.

Tuple<int, string, bool> tuple = new Tuple<int, string, bool>(1,"princy", true);
Var tupleobj = Tuple.Create(1, "Princy", true); 
In order to access the data inside the tuple, use the following:

string name = tupleobj.Item2;
int age = tupleobj.Item1;
bool obj = tupleobj.Item3;

6. Compiler APIs 

 This feature is supposed to come after C# 5.0 – the APIs will expose whatever knowledge the compiler has about the code to the IDE and the developers, through Syntax Tree APIs, Symbol APIs, Binding and Flow analysis APIs and Emit APIs.

You can use following References for more details.

7. Windows Runtime Support

C# and .NET now have deep integration with the Windows Runtime. C# project can compiled into a WinMD file and then referenced from a HTML/JavaScript project. WinRT’s flavor of COM uses the same metadata format used by the Common Language Runtime. This information is stored in WINMD files that show the structure, though not the implementation, of all the public classes. Windows Runtime returns an HRESULT instead of throwing an exception. For well-known HRESULT values, the corresponding exception is thrown, otherwise a COMException is used.

Not able to install SqlServer 2008 says Restart computer failed

When you are trying to install SQL server on your computer and because of any other installation or any process some files are pending for renaming hence this happened.




Steps to solve this problem

- Open the run window

- Type regedit to open  registry editor.

- Search for following value in registry.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

- Double click the PendingFIleRenameOperations and once you will double click it a dialog window would be appeared and simply press the delete key and click OK

Now you would be able to install your SQL server. Please leave your comments if this post helps you.


LINQ Aggregate and Sum

using System;

using System.Linq;

using System.Collections;

using System.Collections.Generic;

 

public class LINQDemo4 {

    public static void Main() {

        IEnumerable<int> intSequence = Enumerable.Range(1, 10);

        foreach (int item in intSequence)

            Console.WriteLine(item);

        int sum = intSequence.Aggregate(0, (s, i) => s + i);

        Console.WriteLine(sum);

    }

}

 

LINQ Aggregate Prototype

using System;

using System.Linq;

using System.Collections;

using System.Collections.Generic;

 

public class LINQDemo3 {

    public static void Main() {

        int N = 5;

        IEnumerable<int> intSequence = Enumerable.Range(1, N);

        foreach (int item in intSequence)

            Console.WriteLine(item);

        int agg = intSequence.Aggregate((av, e) => av * e);

        Console.WriteLine("{0}! = {1}", N, agg);

 

    }

}

 

LINQ Aggregate on an array with tenary operator

using System;

using System.Collections;

using System.Collections.Generic;

using System.Text;

using System.Linq;

 

public class LINQDemo2{

   public static void Main(){

       int[] numbers = { 9, 3, 5, 4, 2, 6, 7, 1, 8 };

       var query = numbers.Aggregate(5, (a,b) => ( (a < b) ? (a * b) : a));

    }

}

 

LINQ Aggregate Use

using System;

using System.Collections;

using System.Collections.Generic;

using System.Text;

using System.Linq;

 

public class LINQDemo1 {

    public static void Main() {

        int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        var query = numbers.Aggregate((a, b) => a * b);

    }

}

What is – DML, DDL, DCL and TCL

DML - is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

e.g.: SELECT, UPDATE, INSERT statements

DDL - is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.

e.g.: CREATE, ALTER, DROP statements

DCL -is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

e.g.: GRANT, REVOKE statements

TCL - is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.