Tuesday, 1 November 2016

Asp.Net Catching

Catching is a technique to get frequently used data/ Information /pages instantly without re-processing web page from server.The object is stored in cache memory and deliver to browser when asked , this makes first operation & less load on server . To generate new HTML & data , is costly for server and it is also time consuming also , bit if stored in memory , retrieve data will be much more efficient than retrieve from database.That is the utility of catching .For example , we are developing an e commerce application , price list of item will not change daily , may be change once in a week.Now if we put the price list in catching , then e commerce site will work much faster.Generating a web page need several stage Page request, Page Initialization , Load , validation , rendering , unload new connection establishment with database , query execution , fetching data.But catching , just retrieve data from cache .Net framework in run time key-value map CLR object called cache .A catching is effective till
  • The catching lifetime , whcih has expired
  • The application has released memory
  • In any case ,catching fails
There are three type of catching in Asp.net Output catching , data catching , object catching. The scope of the data catching is within the application domain ,Catching comes under System.Web.Caching namespace .One point to remember , we can clear browser history to clear cache .Cache can be removed cache remove command

Cache.Remove("MyChache");


Output Catching : Output catching stored finally rendered HTML copy to cache memory.It is simple in implementation and very efficient in working .Output catching reduced response time and work still cache expires. @ OutputCache is the directive to declare output catching , several parmeter are there to maintain catching .For example

HTML
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Duration="100" VaryByParam="None" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
   
    </div>
    </form>
</body>
</html>

 C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Thread.Sleep(1000);
        Response.Write("This page generated and cached at:"+System.DateTime.Now.ToString());
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}

Runtime



 In the above example , page generation time is same , when we click on the button , the page is not re created in server , it is being server by catching after the very first time.

Data Caching : It is a technique to catch the data at the end . Data catching is effective as the previous condition satisfied .
  • The catching lifetime , which expires
  • The application released memory
  • In any case , catching does not occurred
Object Catching : Object catching is the catching a object from web page .Catching an object of an page is much more efficient than catch the entire page.Objects catching can catch complex object also .Still now we came to know , what is catching , type of catching and how catching works .Now we will go though parameter & configuration related to catching .First we will learn that .How we can control where catche can be stored .We can define it .The attribute is HttpCacheability.


HttpCacheability.Server :It tells that , the cache can be store any location /client /host/Proxy.

HttpCacheability.ServerAndNoCache :The response is catche at server & client and not any other location like proxy server.

HttpCacheability.Private :It tells that , the catche can be on the client only not on server or proxy server.

HttpCacheability.Public : Catching stored client & shared (proxy) server.
HttpCacheability.NoCache :Disable Catche

Sample Code :

    protected void Button1_Click(object sender, EventArgs e)
    {
         Response.Cache.SetExpires(System.DateTime.Now.AddDays(5);
         Response.Cache.VaryByHeaders["MyCache"]=true;
         Response.Cache.SetCacheability(HttpCacheability.Private);
    }

 Other than this , there are several ways to clear cache & control cache also . For example if we set 
<meta http-equiv="cache-control" content="no-catche" />

The catche will not work for this page , clear catching instantly for this page.
Previous , we learned about  @ OutputCache to set catche in HTML ,Now
@ OutputCache have some attribute


Thursday, 27 October 2016

Microsoft SQL Server Trigger

Microsoft SQL Server have opportunity "Trigger" ."Trigger" is not like stored procedure or SQL Query , which need to execute ."Trigger" is an functionality object which fires himself when data in a table modified (Insert/Update/Delete). The firing will be determined by defination of trigger , when trigger will fired on Insert/Update/delete .Actually trigger is special kind of stored procedure automatically execute on event occur .We can create/alter trigger by simple DML statement.Trigger are generally execute to implement some business rules. , for example when I am creating a student records , it is obvious to create a login for that student.Here ,if we write a trigger which will create a login data when a new student inserted .Trigger will automatically fires when we add a new student and no need ti write extra logic or not extra event is required to create student login.Her is an exaple of trigger


CREATE TRIGGER myTrigger ON tbl_member
FOR INSERT,UPDATE, DELETE
AS
SELECT MEMBER_ID,MEMBER_NAME FROM Inserted
SELECT MEMBER_ID,MEMBER_NAME FROM deleted
--Wirte your next code here

In teh above exaple , we have a table tbl_membe .We have creatde a trigger on tbl_member .We have define the trigger "FOR INSERT,UPDATE, DELETE" .That means , any operation INSERT,UPDATE, DELETE , the trigger will fired .Now , what happen when Insert, Update , Delete happen ? There is a concept of magic table .During Insert/Update/Delte two type of magic table are created .
  1. Insertde
  2. Deleted
  Inserted tahble for Inserted value 
  Deleted table for deleted value
  For updated , both inserted & deleted table works , first deleted then inserted.

Some points to remember
  • Sql Server allow more than one trigger on a table
  • When we have multiple trigger on a table , we can use ,"sp_settriggerorder" to set trigger firing order .For example trigger A will fire first , trigger B will fire next
                              An Example of Trigger

 
CREATE Trigger Mytrigger1 ON [dbo].[tbl_student]
FOR INSERT
AS
DECLARE @l_student_name         VARCHAR(500),
            @l_student_dob          DATETIME,
            @l_student_class      INT,
            @l_student_address      VARCHAR(MAX)

SELECT @l_student_name=student_name,
         @l_student_dob=student_dob,
         @l_student_class=student_class,
         @l_student_address=student_address
                                      FROM INSERTED;
--Insert Audio Table
INSERT INTO tbl_student_audion
(
      student_name,
      student_dob,
      student_class,
      student_address
)
VALUES
(
     @l_student_name,
       @l_student_dob,
       @l_student_class,
       @l_student_address
)  
GO

In the above exaple , a table named tbl_student hilds , students records , when we insert data into tbl_student , the same data will be copied into tbl_student_audit without any extra event for fireing.

How ever , trigger are basically two types 

  1. After Trigger
  2. Instead of trigger
After Trigger
This type of trigger fires automatically after an insert/update/delete .After insert/After update/After Delete .This type of trigger fires only after main operation (Insert data).In the above example we can modify thus

CREATE Trigger Mytrigger1 ON [dbo].[tbl_student]

AFTER INSERT
AS
DECLARE @l_student_name         VARCHAR(500),
            @l_student_dob          DATETIME,
            @l_student_class      INT,
            @l_student_address      VARCHAR(MAX)

SELECT @l_student_name=student_name,
         @l_student_dob=student_dob,
         @l_student_class=student_class,
         @l_student_address=student_address
                                      FROM INSERTED;
--Insert Audio Table
INSERT INTO tbl_student_audion
(
      student_name,
      student_dob,
      student_class,
      student_address
)
VALUES
(
     @l_student_name,
       @l_student_dob,
       @l_student_class,
       @l_student_address
)  
GO
                      In this process , first record are inserted in the tbl_student table and then data copied tbl_student_audit table. If we change it to "After Delete" , the first data will be deleted and the data will be inserted to tbl_student_audit table.After trigger are the only trigger to allow the same record that client application currently has locked(The operation that caused the trigger to fire earlier or first phase.


                     Instead of Insert 
Instead of Insert trigger fires  before the original operation Insert/Update/Delete .Actually it replace the original operation , if an instead of delete trigger exits on a table , when client delete record , the trigger code will be fired and control return to client.Now question is , when we will use Instead of Trigger ? When you modify the changes made by the client before actually posting update , Instead of Trigger used.

 
CREATE Trigger Mytrigger1 ON [dbo].[tbl_student]
ALTER DELETE
AS
DECLARE @l_student_name         VARCHAR(500),
            @l_student_dob          DATETIME,
            @l_student_class      INT,
            @l_student_address      VARCHAR(MAX)

SELECT @l_student_name=student_name,
         @l_student_dob=student_dob,
         @l_student_class=student_class,
         @l_student_address=student_address
                                      FROM DELETED;
--Insert Audio Table
INSERT INTO tbl_student_audion
(
      student_name,
      student_dob,
      student_class,
      student_address
)
VALUES
(
     @l_student_name,
       @l_student_dob,
       @l_student_class,
       @l_student_address
)  
GO

Now , if i have a multiple trigger on a table , how to disable or on/off trigger ?
The syntax of trigger enable /disable is

ALTER TABLE table_name DISABLE TRIGGER tr_name
ALTER TABLE table_name ENABLE TRIGGER tr_name 

For example  , i want to disable "Mytrigger1" trigger from "tbl_student"
The sql will be

ALTER TABLE tbl_student ENABLE TRIGGER Mytrigger1

A Practical Example
 
--I am creating two table test1 and test2
 CREATE TABLE tests1
 (
 id INT IDENTITY,
 sname VARCHAR(50),
 age INT
 )
 CREATE TABLE tests2
 (
 id INT IDENTITY,
 sname VARCHAR(50),
 age INT
 )
 --I am inserting value to tests1
 INSERT INTO tests1(sname,age)
 VALUES('Name1',12)
 GO
 INSERT INTO tests1(sname,age)
 VALUES('Name2',13)

 --Now table test1 has 2 records and test2 is empty


CREATE Trigger Mytrigger1 ON [dbo].[tests1]
AFTER INSERT
AS
DECLARE @l_sname  VARCHAR(50),
        @l_age    INT
       
--Initialised variable
SELECT @l_sname='',
       @l_age=NULL
      
--get value from test1 into variable
SELECT @l_sname=sname,
       @l_age=age
       FROM INSERTED;

--insert data to test2
 INSERT INTO tests2(sname,age)
 SELECT @l_sname,@l_age

GO
---Now i am again addtin data to tests1
 INSERT INTO tests1(sname,age)
 VALUES('Name2',13)

 ---trigger will fires and put data to tests2

SELECT * FROM tests2

 
        

                      




Tuesday, 25 October 2016

017 Weekend Tour Murshidabad

Murshidabad Tour :
Murshidabad is a district of West Bengal , India . A land of Nawab tells history of Bengal and its culture .The most attractive place to visit Hazarduari Place Museum which is under Archeological Survey of India , Other place are Katra Masjid , Kathgola Garden , Jahan Khosa Garden , Khosh Bagh .Imambara , Tafarganj cemetery , Motijil ect . Mushidabad is situated at the Bank of Bhagirathi river also famous for  silk sari , it tell the story of glory of Independent Bengal During the British rule in India.













Place  to Stay : There are a lot of Hotels (Budget & Standard) in and around Mushidabad .But during the winter & festive season , a lot of tourist comes here to visit Hazar Duari place , it is recommended to Book hotel before.

How to reach : A lot of Bus services are available to reach Murshidabad from Kolkata .Kolkata-Berhampur bus are easily available from esplanade .By train Bhagirathi Express , Lalgola Passenger are there to reach Murshidabad.









Hazarduari palace Museum is situated near Lalbag , it is open for tourist , the precious historical article well preserved here , painting ,furniture , decorated pot of Mughal regime.There are also  two pairs of Mirror in the museum , that are placed 90 degree in such , one can other face but not his own.You can see Gallery of Armour ,Knives ,pistol ,old gun ,Arrow rifles tells the story of Nawab regime.
Khtra Masjit is one of the attraction of Mushidabad .It was build in 1723 and Mushid Quli khan , the famous was buried under staircase of entrance.A great heart touching story is there , guide will explain the story .







Kathgola Garden is another attraction of Murshidabad . Kathgola means black rose , Guide tells that black rose cultivated here earlier.The place is now privately own , here you will also see ancient painting , mirror ,furniture and have attractive and thrilling past story.Guide will told you the past , guide is mandatory here.
Motjil , Means pearl pond , Guide says that in the past pearl cultivated here , Motijil park is a good spot for tourist , beautiful green park , well decorated , well planned is popular among tourist.In the evening light and sound (fountain & music) performance is shown here.







Monday, 24 October 2016

View State Management ASP.Net

View State Management ASP.Net
 
ASP.Net is stateless , that means when we submit page to server , server generate new HTML for that page and deliver us.The value we entered  , get loss .For Example we have entered some information of student and send it to Server , when server return the page , the data i have entered losses.

To solve the problem , different framework introduced different technique .In ASP.Net , there are two type of technique , server Based & Client Based . 


View State is a good technique to handle State Management .View State is actually a hidden field which hold data in base 64 encrypted format.If you go to view HTML of the page , you will notice

It is always recomended to use  as little as possible , view state make extra overhead on perfoemance ,but little .We can enable/disable bu enter enableViewState=true/false.


Now we will discuss how , view state overhead effect .We have data and running two mode  
enableViewState=true/false .Let us see the performance.





Now , notice size of page increase , that means , it will take more time with View State , that means View State has a effect on Page performance.An extra overload make a page little bit slow in loading.

Now , can we control page level view state & control level view state ? can we do disable page view state and enable control view state , the answer is 'yes' , Asp.Net offer this solution also .In the page top just write enableViewState=false , this makes , page view state off , now we can turn on control of ASP.Net ViewStatemode enable disable will enable / disable will enable /disable control by control basis.

Some point to remember

  •   View State Loaded after page_init.
  •   View State created after page_prerender.
  •   View State is encrypted base 64 algorithm.                                                                                                     There are also encryption  option on View State , we can do it elthier page level
  •  
   OR 

Three Option are
Always  : Always encrypt view state.
Auto :encryption if the control on thre page request it.
Never :Recommended not use
  
                                         






বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...