Monday, 6 April 2015

SQL SERVER – Busiest Database in SQl SERVER using Query

DMV sys.dm_exec_query_stats contained columns total_logical_reads, total_logical_writes, sql_handle. Column sql_handle can help to to determine the original query by CROSS JOINing DMF sys.dm_exec_sql_text. From DMF sys.dm_exec_sql_text Database ID and from Database ID can be figured out very quickly.


SELECT SUM(deqs.total_logical_reads) TotalPageReads,
SUM(deqs.total_logical_writes) TotalPageWrites,
CASE
WHEN DB_NAME(dest.dbid) IS NULL THEN 'AdhocSQL'
ELSE DB_NAME(dest.dbid) END Databasename
FROM sys.dm_exec_query_stats deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
GROUP BY DB_NAME(dest.dbid)



Wednesday, 19 February 2014

How can Create DLL File and Use it in .NET Application

How can Create DLL File and Use it in .NET Application

 

If there is some reusable code ,which has to be used in more than one application,instead of specify the same code again and again,we can make a DLL File. DLL can not be execute independently.

There are some steps to make a .dll file and use it in .Net Application.Please follow steps one by one which are given below.
Step1:- First open your visual studio->go File->New Project->Select class Library->Click OK.
see it:-
 
 
Step2:- First open solution Explorer->Right click on  dll exampe->Add Reference->click on .NET->Select System.Windows.Forms->click OK.
 
 
 
Step3:- Write the following code which are given below:-
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace dllexample
{
    public class Class1
    {
        public void sum(int i, int ii)
        {
            int res = i + ii;
 
            MessageBox.Show(res.ToString());
        }
 
        public void multi(int i, int ii)
        {
            int res = i *ii;
            MessageBox.Show(res.ToString());
        }
 
    }
}
 
 
 
 
 
Step:4- Compile the program (Press F6).

Step5:- Now again open New Project->Select WindowsFormsApplication-> Click OK->Make the design which is as shown below:-
 
 
 
Step6:- Open Solution Explorer->Right click on solution Explorer->Click Add Reference->select Browse->Go dllexample File->Bin->Debug->select dlleample->OK.
 
 
 
 
 
 

 
Step7:-   Double click on Getsum and Getmultiple button and write the following which are given below.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            dllexample.Class1 obj = new dllexample.Class1();
           int a=Convert.ToInt32(textBox1.Text);
            int b=Convert.ToInt32(textBox2.Text);
        obj.sum(a,b);
             
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
            dllexample.Class1 obj = new dllexample.Class1();
            int a= Convert.ToInt32(textBox3.Text);
            int b = Convert.ToInt32(textBox4.Text);
            obj.multi(a,b);
        }
    }
}
see it:  
 
 
Step7:- Now Run the program (press F5) ,the output of program is shown below :-
see it:- 
 

 

How to implement cookie in ASP.NET Websites

How to implement cookie in ASP.NET Websites

 

ookie is a small text file which can be used to store the user specific information for personalised the web pages. It stores the data at the user end not server side.When a browser requests a web page again,the cookie is sent along with the request.The web server then retrieves the information from the cookie.In this tutorial i will implement two types of cookie which are given below:-
     1. ) Non Persistent cookie(Temporary cookie) :-
It is known as Temporary cookie.This type of cookie resides within browser memory,So it is called session cookie also.
There are some steps to implement the Non persistent cookie in ASP.NET Website which are given below:-
Step 1:- First open your visual studio--> File-->New-->Website-->ASP.NET Empty website-->OK -->open solution Explorer-->Add a New web forms --> drag and drop label,Text Box,check box,SQL Datasource and Button control on the form as shown below:-

 

Step 2:- Now Add a Database.mdf file --> make student table --> Add some values Id and Password as shown below:-

 


 

 

 

Note:- If you face any problem visit below link:-

  1. Add .mdf Database  on ASP.NET Website
  2. Solve sql server problems
Step 3:-  Now Double click on Login Button and Write the following codes:-
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=.;
AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;
User Instance=True;");
        con.Open();
        String str = "select count(*) from student where id='" + TextBox1.Text + "'and pass='" + TextBox2.Text + "'";
        SqlCommand cmd = new SqlCommand(str, con);
        int obj = Convert.ToInt32(cmd.ExecuteScalar());
        if (obj > 0)
        {
            if (CheckBox1.Checked)
            {
                HttpCookie mycookie = new HttpCookie(TextBox1.Text, TextBox2.Text);
                Response.Cookies.Add(mycookie);
            }

            Response.Redirect("default.aspx");
        }
        else
            Label4.Text = "invalid username or password";
        con.Close();
    }
}

Step 4:- Now Run the Application-->Filed the required field and check the Remember Me Box as shown below:-




Step 5:-Now press login Button--.you can find the browser cookie data by clicking on certificate as shown below:-




Step 6:- Now Run again your application -->you will see that id and password  field  automatically filled through the cookie data as shown below:-




Note:- This type of cookie data resides in the browser memory. when we close the browser then data is lost.
     2. ) Persistent Cookie:- 
This type of cookie resides within  client hard disk till the time ,it Expiry time is over.It stores the data in the user hard disk. 
There are some steps to implement the persistent cookie on the ASP.NET website.which are given below:-
Step 1:- First open your visual studio--> File-->New-->Website-->ASP.NET Empty website-->OK -->open solution Explorer-->Add a New web forms --> drag and drop label,Text Box,check box,sql Datasource and Button control on the form as shown below:-




Step 2:- Now Double click on Login Button and write the following  codes which are given below:-

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class persistantcookies : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=.;
AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;
User Instance=True;");
        con.Open();
        String str = "select count(*) from student where id='" + TextBox1.Text + "'and pass='" + TextBox2.Text + "'";
        SqlCommand cmd = new SqlCommand(str, con);
        int obj = Convert.ToInt32(cmd.ExecuteScalar());
        if (obj > 0)
        {
            if (CheckBox1.Checked)
            {
                HttpCookie mycookie = new HttpCookie(TextBox1.Text, TextBox2.Text);
                mycookie.Expires = DateTime.Now.AddDays(5);
                Response.Cookies.Add(mycookie);
            }

            Response.Redirect("default.aspx");
        }
        else
            Label4.Text = "invalid username or password";
        con.Close();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("tempcookies.aspx");
    }
}

Step 3:- Now Run the Application --> filled the required field  details -->check the Remember Me box as shown below:-




Step 4:- Now press Login Button.see  output:-
 



 Note:- This type of cookie store the id and password Information in a text file in user hard disk.
Step 5:-  To view the cookie data in computer hard disk visit following links.
For Internet Explorer:-
Windows 7 and Windows Vista has 2 cookies folders:-
  1. C:\Users\Your User Name\AppData\Roaming\Microsoft\Windows\Cookies
  2. C:\Users\Your User Name\AppData\Roaming\Microsoft\Windows\Cookies\Low
For chrome Browser:-

  1. C:\Users\Your User Name\AppData\Local\Google\Chrome\User Data\Default\Local Storage
Now i am going to show you cookie data(text file)for our application.You can enter above link in any Browser or window explorer ,you can easily find cookie data(text file).
I have enter above link in window Explorer:-
C:\Users\Ramashanker\AppData\Roaming\Microsoft\Windows\Cookies




Note:- Most of the attack found on your cookie data that resides in your hard disk memory  . You will have to seen many account easily  compromised through client's cookie data.
.Every Browser store cookies data in different different location in your system.In persistent cookie i have used Interner Explore Browser.