Thursday, October 23, 2014

Login failed for user 'NT AUTHORITY\NETWORK SERVICE' [Solved]

The solution that resolved my problem was:
  1. Login to SqlExpress via SQL Server Management Studio
  2. Go to the "Security" directory of the database
  3. Right-click the Users directory
  4. Select "New User..."
  5. Add 'NT AUTHORITY\NETWORK SERVICE' as a new user
  6. In the Data Role Membership area, select db_owner
  7. Set server roles "Public" and "Sysadmin"
  8. Click OK
    Here's a screenshot of the above: 

Wednesday, October 22, 2014

HTTP Error 503. The service is unavailable in IIS [Solved]

HTTP Error 503. The service is unavailable in IIS  is caused if application pool is paused or disabled as shown in the picture below:



Steps to solve HTTP Error 503. The service is unavailable are as follows:

Step 1: Open IIS and look for the  application pool of the selected website. here in this example the website name is test.
Step 2: Select the Application Pool as shown in the diagram below:


Step 3:Write click on the website name in the Application Pool and then click  on Start as shown in the picture below:


Browse the website and the error would be resolved.

Monday, September 15, 2014

Linq with Datatable : Asp.net C#

1. Show all data
********************************
 protected void Button1_Click(object sender, EventArgs e)
    {
        string srt = @"select e.EmployeeId,d.Designation,u.username,u.userpwd from Employees e 
                    inner join DesignationMaster d on d.Designationid=e.DesignationID
                    inner join userdet u on u.EmpId=e.EmployeeId";
        SqlDataAdapter adt = new SqlDataAdapter(srt, con);
        DataTable dt = new DataTable();
        adt.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

Output
********************************
Image1


2. Show all Asst.Professor
********************************
 protected void Button2_Click(object sender, EventArgs e)
    {
        string srt = @"select e.EmployeeId,d.Designation,u.username,u.userpwd from Employees e 
                    inner join DesignationMaster d on d.Designationid=e.DesignationID
                    inner join userdet u on u.EmpId=e.EmployeeId";
        SqlDataAdapter adt = new SqlDataAdapter(srt, con);
        DataTable dt = new DataTable();
        adt.Fill(dt);
       


        EnumerableRowCollection<DataRow> filter = from row in dt.AsEnumerable() where row.Field<string>("Designation") == "Asst.Professor" select row;
        DataView DV = new DataView();
        DV = filter.AsDataView();
        GridView1.DataSource = DV;
        GridView1.DataBind();
    }

Output
********************************
Image2


3. Filer based on user name
********************************
 protected void Button3_Click(object sender, EventArgs e)
    {
        string srt = @"select e.EmployeeId,d.Designation,u.username,u.userpwd from Employees e 
                    inner join DesignationMaster d on d.Designationid=e.DesignationID
                    inner join userdet u on u.EmpId=e.EmployeeId";
        SqlDataAdapter adt = new SqlDataAdapter(srt, con);
        DataTable dt = new DataTable();
        adt.Fill(dt);

        EnumerableRowCollection<DataRow> filter = from row in dt.AsEnumerable() where row.Field<string>("username").Contains(TextBox1.Text) select row;

        DataView dv = new DataView();
        dv = filter.AsDataView();
        GridView1.DataSource = dv;
        GridView1.DataBind();

    }

Output
********************************
Image3

Linq Simple Example with Array C#


  protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "";
        int[] a = { 1, 5, 4, 8, 9, 6 };

        Label1.Text = "Original Array";

        for (int i = 0; i < a.Length; i++)
        {
            Label1.Text += "<br>" + a[i].ToString();
        }

        Label1.Text = "<br>Linq";

        var elements =from element in a where element>5 select element;

        foreach (var x in elements)
        {
            Label1.Text += "<br>" + x;
        }

    }
Output
OutPut Image