Sunday 30 October 2016

SQL Database Authentication error while using Entity Framework(Solved)

Db Authentication error

1.Open SQL Server Management Studio

2.Db -> Security -> Logins -> BUILTIN\Users -> right click -> Properties -> Server Roles -> select the options you want -> click ok

3.Now try with application.

Wednesday 5 October 2016

Difference between Convert and Parse

Both int.Parse and Convert.ToInt32 are used to convert string into the integer but Only difference between them is to Convert.ToInt32 handle null and returns '0' as output and int.parse is not going to handle NULL and will give a Argument Null Exception

  • If you've got a string, and you expect it to always be an integer (say, if some web service is handing you an integer in string format), you'd use Int32.Parse().
  • If you're collecting input from a user, you'd generally use Int32.TryParse(), since it allows you more fine-grained control over the situation when the user enters in invalid input.
  • Convert.ToInt32() takes an object as its argument, and I believe it invokes Int32.TryParse()when it finds that the object taken as the argument is a string.
    Convert.ToInt32() also does not throw ArgumentNullException when it's argument is null the way Int32.Parse() does. That also means that Convert.ToInt32() is probably a wee bit slower than Int32.Parse(), though in practice, unless you're doing a very large number of iterations in a loop, you'll never notice it.

Hash Set best example in C#

Example Here
HashSet is an optimized set collection. It helps eliminates duplicate strings or elements in an array. It provides a simple syntax for taking the union of elements in a set. This is performed in its constructor.

C# program that uses HashSet on duplicates

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
 // Input array that contains three duplicate strings.
 string[] array1 = { "cat", "dog", "cat", "leopard", "tiger", "cat" };

 // Display the array.
 Console.WriteLine(string.Join(",", array1));

 // Use HashSet constructor to ensure unique strings.
 var hash = new HashSet<string>(array1);

 // Convert to array of strings again.
 string[] array2 = hash.ToArray();

 // Display the resulting array.
 Console.WriteLine(string.Join(",", array2));
    }
}

Output

cat,dog,cat,leopard,tiger,cat
cat,dog,leopard,tiger

Monday 3 October 2016

Run and install ASP through CMD prompt.(IIS error 500.21 solved)

This issue can be resolved by using one of the following method:

Method 1: Enable the Directory Browsing feature in IIS (Recommended)

To resolve this problem, follow these steps:
  1. Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
  2. In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
  3. In the Features view, double-click Directory Browsing.
  4. In the Actions pane, click Enable.

Method 2: Add a default document

To resolve this problem, follow these steps:
  1. Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
  2. In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
  3. In the Features view, double-click Default Document.
  4. In the Actions pane, click Enable.
  5. In the File Name box, type the name of the default document, and then click OK.

Example here
//while using IIS enable Directory Browsing

steps:
1.Open CMD prompt run as admin mode

2.CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
*press enter
3.aspnet_regiis -i
*press enter