INSERT:-
========================
CREATE PROCEDURE SP_INSERT_VALUES
(
@ProdName char(50), @active bit, @SortOrder int
)
as
INSERT INTO atmt_products (ProdName,active,SortOrder )
VALUES
(@ProdName,@active,@SortOrder)
return @@identity
GO
=================================
UPDATE:-
===========================
CREATE PROCEDURE SP_UPDATE_VALUES
(
@prodid int, @ProdName Nchar(50), @active bit, @SortOrder int)
as
UPDATE atmt_products SET ProdName=@ProdName,active=@active,SortOrder=@SortOrder
WHERE
prodid=@prodid
GO
==========================
DELETE:-
========================
CREATE PROCEDURE SP_DELETE
(
@prodid int
)
as
delete from atmt_products WHERE prodid=@prodid
GO
Wednesday, April 16, 2008
TRIGGERS
The SQL CREATE TRIGGER statement provides a way for the database management system to actively control, monitor, and manage a group of tables whenever an insert, update, or delete operation is performed. The statements specified in the SQL trigger are executed each time an SQL insert, update, or delete operation is performed. An SQL trigger may call stored procedures or user-defined functions to perform additional processing when the trigger is executed.
Unlike stored procedures, an SQL trigger cannot be directly called from an application. Instead, an SQL trigger is invoked by the database management system on the execution of a triggering insert, update, or delete operation. The definition of the SQL trigger is stored in the database management system and is invoked by the database management system, when the SQL table, that the trigger is defined on, is modified.
Implementing Triggers in SQL Server 2000
Triggers are special types of Stored Procedures that are defined to execute automatically in place of or after data modifications. They can be executed automatically on the INSERT, DELETE and UPDATE triggering actions.
There are two different types of triggers in Microsoft SQL Server 2000. They are INSTEAD OF triggers and AFTER triggers. These triggers differ from each other in terms of their purpose and when they are fired. In this article we shall discuss each type of trigger.
First of all, let's create a sample database with some tables and insert some sample data in those tables using the script below:
Create Database KDMNN
GO
USE KDMNN
GO
CREATE TABLE [dbo].[User_Details] (
[UserID] [int] NULL ,
[FName] [varchar] (50) NOT NULL ,
[MName] [varchar] (50) NULL ,
[LName] [varchar] (50) NOT NULL ,
[Email] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[User_Master] (
[UserID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [varchar] (50) NULL ,
[Password] [varchar] (50) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[User_Master] WITH NOCHECK ADD
CONSTRAINT [PK_User_Master] PRIMARY KEY CLUSTERED
(
[UserID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[User_Details] ADD
CONSTRAINT [FK_User_Details_User_Master] FOREIGN KEY
(
[UserID]
) REFERENCES [dbo].[User_Master] (
[UserID]
)
GO
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
SELECT 'Navneeth','Navneeth' UNION
SELECT 'Amol','Amol' UNION
SELECT 'Anil','Anil' UNION
SELECT 'Murthy','Murthy'
INSERT INTO USER_DETAILS(USERID, FNAME, LNAME, EMAIL)
SELECT 1,'Navneeth','Naik','navneeth@kdmnn.com' UNION
SELECT 2,'Amol','Kulkarni','amol@kdmnn.com' UNION
SELECT 3,'Anil','Bahirat','anil@kdmnn.com' UNION
SELECT 4,'Murthy','Belluri','murthy@kdmnn.com'
AFTER Triggers
The type of trigger that gets executed automatically after the statement that triggered it completes is called an AFTER trigger. An AFTER trigger is a trigger that gets executed automatically before the transaction is committed or rolled back.
Using the below script, first we shall create a trigger on the table USER_MASTER for the INSERT event of the table.
USE KDMNN
Go
CREATE TRIGGER trgInsert
ON User_Master
FOR INSERT
AS
Print ('AFTER Trigger [trgInsert] – Trigger executed !!')
GO
BEGIN TRANSACTION
DECLARE @ERR INT
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
VALUES('Damerla','Damerla')
SET @ERR = @@Error
IF @ERR = 0
BEGIN
ROLLBACK TRANSACTION
PRINT 'ROLLBACK TRANSACTION'
END
ELSE
BEGIN
COMMIT TRANSACTION
PRINT 'COMMIT TRANSACTION'
END
Output
AFTER Trigger [trgInsert] – Trigger executed !!
(1 row(s) affected)
ROLLBACK TRANSACTION
By looking at the output, we can conclude that before the transaction is rolled back or committed, the AFTER trigger gets executed automatically. A table can have several AFTER triggers for each of the three triggering actions i.e., INSERT, DELETE and UPDATE. Using the below script, we shall create two triggers on the table User_Master for the INSERT triggering action.
CREATE TRIGGER trgInsert2
ON User_Master
FOR INSERT
AS
BEGIN
Print ('AFTER Trigger [trgInsert2] – Trigger executed !!')
END
GO
CREATE TRIGGER trgInsert3
ON User_Master
FOR INSERT
AS
BEGIN
Print ('AFTER Trigger [trgInsert3] – Trigger executed !!')
END
GO
BEGIN TRANSACTION
DECLARE @ERR INT
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
VALUES('Damerla','Damerla')
SET @ERR = @@Error
IF @ERR = 0
BEGIN
ROLLBACK TRANSACTION
PRINT 'ROLLBACK TRANSACTION'
END
ELSE
BEGIN
COMMIT TRANSACTION
PRINT 'COMMIT TRANSACTION'
END
Output
AFTER Trigger [trgInsert] – Trigger executed !!
AFTER Trigger [trgInsert2] – Trigger executed !!
AFTER Trigger [trgInsert3] – Trigger executed !!
(1 row(s) affected)
ROLLBACK TRANSACTION
Triggers can be used in the following scenarios, such as if the database is de-normalized and requires an automated way to update redundant data contained in multiple tables, or if customized messages and complex error handling are required, or if a value in one table must be validated against a non-identical value in another table.
Triggers are a powerful tool that can be used to enforce the business rules automatically when the data is modified. Triggers can also be used to maintain the data integrity. But they are not to maintain data integrity. Triggers should be used to maintain the data integrity only if you are unable to enforce the data integrity using CONSTRAINTS, RULES and DEFAULTS. Triggers cannot be created on the temporary tables.
Unlike stored procedures, an SQL trigger cannot be directly called from an application. Instead, an SQL trigger is invoked by the database management system on the execution of a triggering insert, update, or delete operation. The definition of the SQL trigger is stored in the database management system and is invoked by the database management system, when the SQL table, that the trigger is defined on, is modified.
Implementing Triggers in SQL Server 2000
Triggers are special types of Stored Procedures that are defined to execute automatically in place of or after data modifications. They can be executed automatically on the INSERT, DELETE and UPDATE triggering actions.
There are two different types of triggers in Microsoft SQL Server 2000. They are INSTEAD OF triggers and AFTER triggers. These triggers differ from each other in terms of their purpose and when they are fired. In this article we shall discuss each type of trigger.
First of all, let's create a sample database with some tables and insert some sample data in those tables using the script below:
Create Database KDMNN
GO
USE KDMNN
GO
CREATE TABLE [dbo].[User_Details] (
[UserID] [int] NULL ,
[FName] [varchar] (50) NOT NULL ,
[MName] [varchar] (50) NULL ,
[LName] [varchar] (50) NOT NULL ,
[Email] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[User_Master] (
[UserID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [varchar] (50) NULL ,
[Password] [varchar] (50) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[User_Master] WITH NOCHECK ADD
CONSTRAINT [PK_User_Master] PRIMARY KEY CLUSTERED
(
[UserID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[User_Details] ADD
CONSTRAINT [FK_User_Details_User_Master] FOREIGN KEY
(
[UserID]
) REFERENCES [dbo].[User_Master] (
[UserID]
)
GO
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
SELECT 'Navneeth','Navneeth' UNION
SELECT 'Amol','Amol' UNION
SELECT 'Anil','Anil' UNION
SELECT 'Murthy','Murthy'
INSERT INTO USER_DETAILS(USERID, FNAME, LNAME, EMAIL)
SELECT 1,'Navneeth','Naik','navneeth@kdmnn.com' UNION
SELECT 2,'Amol','Kulkarni','amol@kdmnn.com' UNION
SELECT 3,'Anil','Bahirat','anil@kdmnn.com' UNION
SELECT 4,'Murthy','Belluri','murthy@kdmnn.com'
AFTER Triggers
The type of trigger that gets executed automatically after the statement that triggered it completes is called an AFTER trigger. An AFTER trigger is a trigger that gets executed automatically before the transaction is committed or rolled back.
Using the below script, first we shall create a trigger on the table USER_MASTER for the INSERT event of the table.
USE KDMNN
Go
CREATE TRIGGER trgInsert
ON User_Master
FOR INSERT
AS
Print ('AFTER Trigger [trgInsert] – Trigger executed !!')
GO
BEGIN TRANSACTION
DECLARE @ERR INT
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
VALUES('Damerla','Damerla')
SET @ERR = @@Error
IF @ERR = 0
BEGIN
ROLLBACK TRANSACTION
PRINT 'ROLLBACK TRANSACTION'
END
ELSE
BEGIN
COMMIT TRANSACTION
PRINT 'COMMIT TRANSACTION'
END
Output
AFTER Trigger [trgInsert] – Trigger executed !!
(1 row(s) affected)
ROLLBACK TRANSACTION
By looking at the output, we can conclude that before the transaction is rolled back or committed, the AFTER trigger gets executed automatically. A table can have several AFTER triggers for each of the three triggering actions i.e., INSERT, DELETE and UPDATE. Using the below script, we shall create two triggers on the table User_Master for the INSERT triggering action.
CREATE TRIGGER trgInsert2
ON User_Master
FOR INSERT
AS
BEGIN
Print ('AFTER Trigger [trgInsert2] – Trigger executed !!')
END
GO
CREATE TRIGGER trgInsert3
ON User_Master
FOR INSERT
AS
BEGIN
Print ('AFTER Trigger [trgInsert3] – Trigger executed !!')
END
GO
BEGIN TRANSACTION
DECLARE @ERR INT
INSERT INTO USER_MASTER(USERNAME, PASSWORD)
VALUES('Damerla','Damerla')
SET @ERR = @@Error
IF @ERR = 0
BEGIN
ROLLBACK TRANSACTION
PRINT 'ROLLBACK TRANSACTION'
END
ELSE
BEGIN
COMMIT TRANSACTION
PRINT 'COMMIT TRANSACTION'
END
Output
AFTER Trigger [trgInsert] – Trigger executed !!
AFTER Trigger [trgInsert2] – Trigger executed !!
AFTER Trigger [trgInsert3] – Trigger executed !!
(1 row(s) affected)
ROLLBACK TRANSACTION
Triggers can be used in the following scenarios, such as if the database is de-normalized and requires an automated way to update redundant data contained in multiple tables, or if customized messages and complex error handling are required, or if a value in one table must be validated against a non-identical value in another table.
Triggers are a powerful tool that can be used to enforce the business rules automatically when the data is modified. Triggers can also be used to maintain the data integrity. But they are not to maintain data integrity. Triggers should be used to maintain the data integrity only if you are unable to enforce the data integrity using CONSTRAINTS, RULES and DEFAULTS. Triggers cannot be created on the temporary tables.
NORMALIZATION
What is normalization?
Normalization is the process of designing a data model to efficiently store data in a database. The end result is that redundant data is eliminated, and only data related to the attribute is stored within the table.
For example, let's say we store City, State and ZipCode data for Customers in the same table as Other Customer data. With this approach, we keep repeating the City, State and ZipCode data for all Customers in the same area. Instead of storing the same data again and again, we could normalize the data and create a related table called City. The "City" table could then store City, State and ZipCode along with IDs that relate back to the Customer table, and we can eliminate those three columns from the Customer table and add the new ID column.
Normalization rules have been broken down into several forms. People often refer to the third normal form (3NF) when talking about database design. This is what most database designers try to achieve: In the conceptual stages, data is segmented and normalized as much as possible, but for practical purposes those segments are changed during the evolution of the data model. Various normal forms may be introduced for different parts of the data model to handle the unique situations you may face.
Whether you have heard about normalization or not, your database most likely follows some of the rules, unless all of your data is stored in one giant table. We will take a look at the first three normal forms and the rules for determining the different forms here.
Rules for First Normal Form (1NF)
Eliminate repeating groups. This table contains repeating groups of data in the Software column.
Rules for second Normal Form (2NF)
Eliminate redundant data plus 1NF. This table contains the name of the software which is redundant data.
Rules for Third Normal Form (3NF)
Eliminate columns ‘not dependent on key’ plus 1NF and 2NF. In this table, we have data that contains both data about the computer and the user.
To eliminate columns not dependent on the key, we would create the following tables. Now the data stored in the computer table is only related to the computer, and the data stored in the user table is only related to the user.
What does normalization have to do with SQL Server?
To be honest, the answer here is nothing. SQL Server, like any other RDBMS, couldn't care less whether your data model follows any of the normal forms. You could create one table and store all of your data in one table or you can create a lot of little, unrelated tables to store your data. SQL Server will support whatever you decide to do. The only limiting factor you might face is the maximum number of columns SQL Server supports for a table.
SQL Server does not force or enforce any rules that require you to create a database in any of the normal forms. You are able to mix and match any of the rules you need, but it is a good idea to try to normalize your database as much as possible when you are designing it. People tend to spend a lot of time up front creating a normalized data model, but as soon as new columns or tables need to be added, they forget about the initial effort that was devoted to creating a nice clean model.
To assist in the design of your data model, you can use the DaVinci tools that are part of SQL Server Enterprise Manager.
Advantages of normalization
1. Smaller database: By eliminating duplicate data, you will be able to reduce the overall size of the database.2. Better performance:
a. Narrow tables: Having more fine-tuned tables allows your tables to have less columns and allows you to fit more records per data page.b. Fewer indexes per table mean faster maintenance tasks such as index rebuilds.c. Only join tables that you need.
Disadvantages of normalization
1. More tables to join: By spreading out your data into more tables, you increase the need to join tables.2. Tables contain codes instead of real data: Repeated data is stored as codes rather than meaningful data. Therefore, there is always a need to go to the lookup table for the value.3. Data model is difficult to query against: The data model is optimized for applications, not for ad hoc querying.
Summary
Your data model design is both an art and a science. Balance what works best to support the application that will use the database and to store data in an efficient and structured manner. For transaction-based systems, a highly normalized database design is the way to go; it ensures consistent data throughout the entire database and that it is performing well. For reporting-based systems, a less normalized database is usually the best approach. You will eliminate the need to join a lot of tables and queries will be faster. Plus, the database will be much more user friendly for ad hoc reporting needs.
Normalization is the process of designing a data model to efficiently store data in a database. The end result is that redundant data is eliminated, and only data related to the attribute is stored within the table.
For example, let's say we store City, State and ZipCode data for Customers in the same table as Other Customer data. With this approach, we keep repeating the City, State and ZipCode data for all Customers in the same area. Instead of storing the same data again and again, we could normalize the data and create a related table called City. The "City" table could then store City, State and ZipCode along with IDs that relate back to the Customer table, and we can eliminate those three columns from the Customer table and add the new ID column.
Normalization rules have been broken down into several forms. People often refer to the third normal form (3NF) when talking about database design. This is what most database designers try to achieve: In the conceptual stages, data is segmented and normalized as much as possible, but for practical purposes those segments are changed during the evolution of the data model. Various normal forms may be introduced for different parts of the data model to handle the unique situations you may face.
Whether you have heard about normalization or not, your database most likely follows some of the rules, unless all of your data is stored in one giant table. We will take a look at the first three normal forms and the rules for determining the different forms here.
Rules for First Normal Form (1NF)
Eliminate repeating groups. This table contains repeating groups of data in the Software column.
Rules for second Normal Form (2NF)
Eliminate redundant data plus 1NF. This table contains the name of the software which is redundant data.
Rules for Third Normal Form (3NF)
Eliminate columns ‘not dependent on key’ plus 1NF and 2NF. In this table, we have data that contains both data about the computer and the user.
To eliminate columns not dependent on the key, we would create the following tables. Now the data stored in the computer table is only related to the computer, and the data stored in the user table is only related to the user.
What does normalization have to do with SQL Server?
To be honest, the answer here is nothing. SQL Server, like any other RDBMS, couldn't care less whether your data model follows any of the normal forms. You could create one table and store all of your data in one table or you can create a lot of little, unrelated tables to store your data. SQL Server will support whatever you decide to do. The only limiting factor you might face is the maximum number of columns SQL Server supports for a table.
SQL Server does not force or enforce any rules that require you to create a database in any of the normal forms. You are able to mix and match any of the rules you need, but it is a good idea to try to normalize your database as much as possible when you are designing it. People tend to spend a lot of time up front creating a normalized data model, but as soon as new columns or tables need to be added, they forget about the initial effort that was devoted to creating a nice clean model.
To assist in the design of your data model, you can use the DaVinci tools that are part of SQL Server Enterprise Manager.
Advantages of normalization
1. Smaller database: By eliminating duplicate data, you will be able to reduce the overall size of the database.2. Better performance:
a. Narrow tables: Having more fine-tuned tables allows your tables to have less columns and allows you to fit more records per data page.b. Fewer indexes per table mean faster maintenance tasks such as index rebuilds.c. Only join tables that you need.
Disadvantages of normalization
1. More tables to join: By spreading out your data into more tables, you increase the need to join tables.2. Tables contain codes instead of real data: Repeated data is stored as codes rather than meaningful data. Therefore, there is always a need to go to the lookup table for the value.3. Data model is difficult to query against: The data model is optimized for applications, not for ad hoc querying.
Summary
Your data model design is both an art and a science. Balance what works best to support the application that will use the database and to store data in an efficient and structured manner. For transaction-based systems, a highly normalized database design is the way to go; it ensures consistent data throughout the entire database and that it is performing well. For reporting-based systems, a less normalized database is usually the best approach. You will eliminate the need to join a lot of tables and queries will be faster. Plus, the database will be much more user friendly for ad hoc reporting needs.
Monday, April 14, 2008
Search Engine Optimization (SEO)
What is Search Engine Optimization (SEO)?
You might have heard of the word SEO mean search engine optimization. Google is major search engine and if you have a website, you can get more traffic on your site by adding it to search engines like google yahoo or msn. There are many ways to add your site to search engines and get crawled.
Search engine optimization is a set of methods aimed at improving the ranking of a website in search engine listings. The term also refers to an industry of consultants that carry out optimization projects on behalf of clients' sites. Search Engines display different kinds of listings in the search engine results pages (SERPs), including: pay-per-click advertisements, paid inclusion listings, and organic search results. SEO is primarily concerned with advancing the goals of a web site by improving the number and position of its organic search results for a wide variety of relevant keywords.
Available general search engines..
Alexa Internet
Ask.com (formerly Ask Jeeves)
Baidu (Chinese)
Exalead (French)
Gigablast
Google
Live Search (formerly MSN Search)
Sogou (Chinese)
Sohu (Chinese)
Yahoo! Search
Ref: http://en.wikipedia.org/wiki/List_of_search_engines
How To Search Engine Optization
---------------------------------
1. Use exact key words, relted to your site. Add key words with large font( more than 14pix)
2. Add social services links in your ste to get more clicks to your site.
3.use validated HTML code
4.use HTML Markups
5. USe Rss, add Atl text for Images.
6.Use sitemap.
7.Use "title" property
8.Don't use Flash/Silverlight, javascript-based MENU.
9.Don't use inline css, use external stylesheets whenever possible
Don't use inline javascript, use external .js-files instead
Remove leave html-comments.
10.Don't forger " title-tag ".
11. Don't USE duplicate content.
Saturday, October 27, 2007
New series of Microsoft Webcasts
Communities and webcasts are great place to learn and share .Is not it?
Here are new series of webcasts for IT PRO by eminent speakersPlease register the corresponding stream.
October 15, 2007(4:00 pm - 5:30 pm)
Infrastructure Architecture - Case Study Review
Infrastructure Architecture - Case Study Review.
Speaker: Ramnish SinghOctober 17, 2007(2:00 pm - 3:00 pm)
SQL Server 2005 - BasicsThis session we will take a look at the various SQL Server 2005 Editions available in the market. We will then take a dive into the various sub-components introduced with SQL Server 2005. The session will build the foundation for getting started with SQL Server 2005.
Speaker: Vinod Kumar October 18, 2007(4:00 pm - 5:30 pm)
SQL Server 2005: Database MaintenanceAlthough many of the concepts of database maintenance in a SQL Server 2005 Environment remain the same as with previous SQL releases, there are several new features. Database snapshots provide a way to revert to a point of consistency, while partial restores allows users to access unaffected files and pages. You can now continue the backup and restore operations after a failure and configure fast recovery during crash recovering and mirroring failover. It is now possible to verify the integrity of data pages during backup and restore operations. Come, hear about all of these and see some of these features in action with me!
Speaker: L Srividya October 19, 2007(4:00 pm - 5:30 pm)
Monitoring SQL Server 2005 PerformanceA number of tools are available to inspect and record activity in a SQL Server installation. Some are built into SQL Server and some are built into the Operating System. Some of these tools include the System monitor, Data Tuning Advisor, Activity Monitor, etc. This session takes you through a few of these tools for troubleshooting and optimizing your SQL Server performance.
Here are new series of webcasts for IT PRO by eminent speakersPlease register the corresponding stream.
October 15, 2007(4:00 pm - 5:30 pm)
Infrastructure Architecture - Case Study Review
Infrastructure Architecture - Case Study Review.
Speaker: Ramnish SinghOctober 17, 2007(2:00 pm - 3:00 pm)
SQL Server 2005 - BasicsThis session we will take a look at the various SQL Server 2005 Editions available in the market. We will then take a dive into the various sub-components introduced with SQL Server 2005. The session will build the foundation for getting started with SQL Server 2005.
Speaker: Vinod Kumar October 18, 2007(4:00 pm - 5:30 pm)
SQL Server 2005: Database MaintenanceAlthough many of the concepts of database maintenance in a SQL Server 2005 Environment remain the same as with previous SQL releases, there are several new features. Database snapshots provide a way to revert to a point of consistency, while partial restores allows users to access unaffected files and pages. You can now continue the backup and restore operations after a failure and configure fast recovery during crash recovering and mirroring failover. It is now possible to verify the integrity of data pages during backup and restore operations. Come, hear about all of these and see some of these features in action with me!
Speaker: L Srividya October 19, 2007(4:00 pm - 5:30 pm)
Monitoring SQL Server 2005 PerformanceA number of tools are available to inspect and record activity in a SQL Server installation. Some are built into SQL Server and some are built into the Operating System. Some of these tools include the System monitor, Data Tuning Advisor, Activity Monitor, etc. This session takes you through a few of these tools for troubleshooting and optimizing your SQL Server performance.
Class and structure
What are similarities between Class and structure ?
Following are the similarities between classes and structures :-v Both can have constructors, methods, properties, fields, constants,enumerations, events, and event handlers.v Structures and classes can implement interface.v Both of them can have constructors with and without parameter.v Both can have delegates and events.(A) What is the difference between Class and structure’s ?Following are the key differences between them :-v Structure are value types and classes are reference types. So structures usestack and classes use heap.v Structures members can not be declared as protected, but class members canbe. You can not do inheritance in structures.v Structures do not require constructors while classes require.v Objects created from classes are terminated using Garbage collector. Structuresare not destroyed using GC.
Following are the similarities between classes and structures :-v Both can have constructors, methods, properties, fields, constants,enumerations, events, and event handlers.v Structures and classes can implement interface.v Both of them can have constructors with and without parameter.v Both can have delegates and events.(A) What is the difference between Class and structure’s ?Following are the key differences between them :-v Structure are value types and classes are reference types. So structures usestack and classes use heap.v Structures members can not be declared as protected, but class members canbe. You can not do inheritance in structures.v Structures do not require constructors while classes require.v Objects created from classes are terminated using Garbage collector. Structuresare not destroyed using GC.
Cache
(B) What is application object ?
Application object can used in situation where we want data to be shared across users globally.
(I)What’s the difference between Cache object and application object ?
The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
(I)How can get access to cache object ?
The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.
(A)What are dependencies in cache and types of dependencies ?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of
dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.Following are the supported dependency
:-
√ File dependency :- Allows you to invalidate a specific cache item when a disk
based file or files change.
√ Time-based expiration :- Allows you to invalidate a specific cache item
depending on predefined time.
√ Key dependency :-Allows you to invalidate a specific cache item depending
when another cached item changes.
(P)Can you show a simple code showing file dependency in cache ?
Partial Class Default_aspx
Public Sub displayAnnouncement()
Dim announcement As String
If Cache(“announcement”) Is Nothing Then
Dim file As New _
System.IO.StreamReader _
(Server.MapPath(“announcement.txt”))
announcement = file.ReadToEnd
file.Close()
Dim depends As New _
System.Web.Caching.CacheDependency _
(Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
End If
Response.Write(CType(Cache(“announcement”), String))
End Sub
Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
displayAnnouncement()
End Sub
End Class
Note :- Above source code can be obtained from CD in “CacheSample”
folder.”Announcement.txt” is in the same folder which you can play around to see the
results.
Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory.Above method first checks is the Cache object nothing , if the cache object is nothing then it moves further to load the cache data from the file.Whenever the file data changes the cache object is removed and
set to nothing.
(A) What is Cache Callback in Cache ?
Cache object is dependent on its dependencies example file based , time based etc.Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.
(B) What are different types of caching using cache object of ASP.NET?
You can use two types of output caching to cache information that is to be transmitted to
and displayed in a Web browser:
√ Page Output Caching
Page output caching adds the response of page to cache object.Later when
page is requested page is displayed from cache rather than creating the
page object and displaying it.Page output caching is good if the site is
fairly static.
√ Page Fragment Caching
If parts of the page are changing, you can wrap the static sections as user
controls and cache the user controls using pagefragment caching.
(B) How can you cache different version of same page using ASP.NET
cache object ?
Output cache functionality is achieved by using “OutputCache” attribute on ASP.NET
page header.Below is the syntax
<%@ OutputCache Duration="20" Location="Server" VaryByParam="state" VaryByCustom="minorversion" VaryByHeader="Accept-Language"%>
√ VaryByParam :- Caches different version depending on input parameters send
through HTTP POST/GET.
√ VaryByHeader:- Caches different version depending on the contents of the
page header.
(A) How will implement Page Fragment Caching ?
Page fragment caching involves the caching of a fragment of the page, rather than the
entire page. When portions of the page need to be dynamically created for each user
request this is best method as compared to page caching.You can wrap Web Forms user
control and cache the control so that these portions of the page don’t need to be recreated
each time.
(B) What are ASP.NET session and compare ASP.NET session with
classic ASP session variables?
ASP.NET session caches per user session state.It basically uses “HttpSessionState” class.
Following are the limitations in classic ASP sessions :-
√ ASP session state is dependent on IIS process very heavily.So if IIS restarts
ASP session variables are also recycled.ASP.NET session can be independent
of the hosting environment thus ASP.NET session can maintained even if IIS
reboots.
√ ASP session state has no inherent solution to work with Web Farms.ASP.NET
session can be stored in state server and SQL SERVER which can support
multiple server.
√ ASP session only functions when browser supports cookies.ASP.NET session
can be used with browser side cookies or independent of it.
(B) Which various modes of storing ASP.NET session ?
√ InProc:- In this mode Session state is stored in the memory space of the
Aspnet_wp.exe process.This is the default setting.If the IIS reboots or web
application restarts then session state is lost.
√ StateServer:-In this mode Session state is serialized and stored in a separate
process (Aspnet_state.exe); therefore, the state can be stored on a separate
computer(a state server).
√ SQL SERVER:- In this mode Session state is serialized and stored in a SQL
Server database.
Session state can be specified inelement of application configuration file.Using State Server and SQL SERVER session state can be shared across web farms but note this comes at speed cost as ASP.NET needs to serialize and deserialize data over network again and again.
(B) What are the other ways you can maintain state ?
Other than session variables you can use the following technique to store state :
√ Hidden fields
√ View state
√ Hidden frames
√ Cookies
√ Query strings
(B) What are benefits and Limitation of using Hidden fields ?
Following are the benefits of using Hidden fields :-
√ They are simple to implement.
√ As data is cached on client side they work with Web Farms.
√ All browsers support hidden field.
√ No server resources are required.
Following are limitations of Hidden field :-
Application object can used in situation where we want data to be shared across users globally.
(I)What’s the difference between Cache object and application object ?
The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
(I)How can get access to cache object ?
The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.
(A)What are dependencies in cache and types of dependencies ?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of
dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.Following are the supported dependency
:-
√ File dependency :- Allows you to invalidate a specific cache item when a disk
based file or files change.
√ Time-based expiration :- Allows you to invalidate a specific cache item
depending on predefined time.
√ Key dependency :-Allows you to invalidate a specific cache item depending
when another cached item changes.
(P)Can you show a simple code showing file dependency in cache ?
Partial Class Default_aspx
Public Sub displayAnnouncement()
Dim announcement As String
If Cache(“announcement”) Is Nothing Then
Dim file As New _
System.IO.StreamReader _
(Server.MapPath(“announcement.txt”))
announcement = file.ReadToEnd
file.Close()
Dim depends As New _
System.Web.Caching.CacheDependency _
(Server.MapPath(“announcement.txt”))
Cache.Insert(“announcement”, announcement, depends)
End If
Response.Write(CType(Cache(“announcement”), String))
End Sub
Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
displayAnnouncement()
End Sub
End Class
Note :- Above source code can be obtained from CD in “CacheSample”
folder.”Announcement.txt” is in the same folder which you can play around to see the
results.
Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory.Above method first checks is the Cache object nothing , if the cache object is nothing then it moves further to load the cache data from the file.Whenever the file data changes the cache object is removed and
set to nothing.
(A) What is Cache Callback in Cache ?
Cache object is dependent on its dependencies example file based , time based etc.Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.
(B) What are different types of caching using cache object of ASP.NET?
You can use two types of output caching to cache information that is to be transmitted to
and displayed in a Web browser:
√ Page Output Caching
Page output caching adds the response of page to cache object.Later when
page is requested page is displayed from cache rather than creating the
page object and displaying it.Page output caching is good if the site is
fairly static.
√ Page Fragment Caching
If parts of the page are changing, you can wrap the static sections as user
controls and cache the user controls using pagefragment caching.
(B) How can you cache different version of same page using ASP.NET
cache object ?
Output cache functionality is achieved by using “OutputCache” attribute on ASP.NET
page header.Below is the syntax
<%@ OutputCache Duration="20" Location="Server" VaryByParam="state" VaryByCustom="minorversion" VaryByHeader="Accept-Language"%>
√ VaryByParam :- Caches different version depending on input parameters send
through HTTP POST/GET.
√ VaryByHeader:- Caches different version depending on the contents of the
page header.
(A) How will implement Page Fragment Caching ?
Page fragment caching involves the caching of a fragment of the page, rather than the
entire page. When portions of the page need to be dynamically created for each user
request this is best method as compared to page caching.You can wrap Web Forms user
control and cache the control so that these portions of the page don’t need to be recreated
each time.
(B) What are ASP.NET session and compare ASP.NET session with
classic ASP session variables?
ASP.NET session caches per user session state.It basically uses “HttpSessionState” class.
Following are the limitations in classic ASP sessions :-
√ ASP session state is dependent on IIS process very heavily.So if IIS restarts
ASP session variables are also recycled.ASP.NET session can be independent
of the hosting environment thus ASP.NET session can maintained even if IIS
reboots.
√ ASP session state has no inherent solution to work with Web Farms.ASP.NET
session can be stored in state server and SQL SERVER which can support
multiple server.
√ ASP session only functions when browser supports cookies.ASP.NET session
can be used with browser side cookies or independent of it.
(B) Which various modes of storing ASP.NET session ?
√ InProc:- In this mode Session state is stored in the memory space of the
Aspnet_wp.exe process.This is the default setting.If the IIS reboots or web
application restarts then session state is lost.
√ StateServer:-In this mode Session state is serialized and stored in a separate
process (Aspnet_state.exe); therefore, the state can be stored on a separate
computer(a state server).
√ SQL SERVER:- In this mode Session state is serialized and stored in a SQL
Server database.
Session state can be specified in
(B) What are the other ways you can maintain state ?
Other than session variables you can use the following technique to store state :
√ Hidden fields
√ View state
√ Hidden frames
√ Cookies
√ Query strings
(B) What are benefits and Limitation of using Hidden fields ?
Following are the benefits of using Hidden fields :-
√ They are simple to implement.
√ As data is cached on client side they work with Web Farms.
√ All browsers support hidden field.
√ No server resources are required.
Following are limitations of Hidden field :-
Subscribe to:
Posts (Atom)