Friday, May 25, 2012

New Elements in HTML5

The internet has changed a lot since HTML 4.01 became a standard in 1999.
Today, some elements in HTML 4.01 are obsolete, never used, or not used the way they were intended to. These elements are removed or re-written in HTML5.
To better handle today's internet use, HTML5 includes new elements for better structure, better form handling, drawing, and for media content.

http://www.w3schools.com/html5/html5_new_elements.asp

Wednesday, May 23, 2012

Diffrence between Sql 2005 and 2008

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107186

Main Features provided in Sql 2008:
Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone
is used.

Table datatype introduced.
Can encrypt the entire database introduced in 2008.
Central Management Server(CMS) is Introduced.  

Diffrence between 3-Tier and mvc-vs-mvp-vs-mvvm

http://nirajrules.wordpress.com/2009/07/18/mvc-vs-mvp-vs-mvvm/

A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model. 

Tuesday, May 1, 2012

Difference between Function and Stored procedure

The following are the differences between a User Defined Function and a Stored Procedure in SQL Server

  1. Stored Procedure support deffered name resolution where as functions do not support deffered name resolution.
  2. User Defined Function can be used in a select statement where as you cannot use a stored procedure in a select statement.
  3. UDF’s cannot return Image, Text where as a StoredProcedure can return any datatype.
  4. In general User Defined Functions are used for computations where as Stored Procedures are used for performing business logic.
  5. UDF should return a value where as Stored Procedure need not.
  6. User Defined Functions accept lesser number of input parameters than Stored Procedures. UDF can have upto 1023 input parameters where as a Stored Procedure can have upto 21000 input parameters.
  7. You cannot use non-deterministic built-in functions in UDF’s. For example functions like GETDATE() etc can not be used in UDFs, but can be used in Stored Procedures.
  8. Temporary Tables can not be used in a UDF where as a StoredProcedure can use Temporary Tables.
  9. UDF can not Execute Dynamic SQL where as a Stored Procedure can execute Dynamic SQL.
  10. User Defined Function does not support error handling where as Stored Procedure support error handling. RAISEERROR or @@ERROR are not allowed in UDFs.

Monday, April 23, 2012

SQL Server script to rebuild all indexes for all tables and all databases

DECLARE @Database VARCHAR(255)   DECLARE @Table VARCHAR(255)  DECLARE @cmd NVARCHAR(500)  DECLARE @fillfactor INT

SET
@fillfactor = 90
DECLARE DatabaseCursor CURSOR FOR 
SELECT
name FROM MASTER.dbo.sysdatabases   WHERE name NOT IN ('master','msdb','tempdb','model','distribution')   ORDER BY
OPEN DatabaseCursor 
FETCH NEXT FROM DatabaseCursor INTO @Database  WHILE @@FETCH_STATUS = 0  BEGIN 

   SET
@cmd = 'DECLARE TableCursor CURSOR FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' +
  table_name + '']'' as tableName FROM '
+ @Database + '.INFORMATION_SCHEMA.TABLES
  WHERE table_type = ''BASE TABLE'''  

  
-- create table cursor 
  
EXEC (@cmd
  
OPEN TableCursor  

  
FETCH NEXT FROM TableCursor INTO @Table  
  
WHILE @@FETCH_STATUS = 0  
  
BEGIN  

       IF
(@@MICROSOFTVERSION / POWER(2, 24) >= 9)
      
BEGIN
          
-- SQL 2005 or higher command
          
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
          
EXEC (@cmd)
      
END
       ELSE
       BEGIN
          
-- SQL 2000 command
          
DBCC DBREINDEX(@Table,' ',@fillfactor
      
END

       FETCH
NEXT FROM TableCursor INTO @Table  
  
END  

   CLOSE
TableCursor  
  
DEALLOCATE TableCursor 

  
FETCH NEXT FROM DatabaseCursor INTO @Database  END 
CLOSE
DatabaseCursor   DEALLOCATE DatabaseCursor

Simple script to backup all SQL Server databases

DECLARE @name VARCHAR(50-- database name  DECLARE @path VARCHAR(256-- path for backup files  DECLARE @fileName VARCHAR(256-- filename for backup  DECLARE @fileDate VARCHAR(20-- used for file name
SET @path 'C:\Backup\' 
SELECT @fileDate CONVERT(VARCHAR(20),GETDATE(),112)
DECLARE db_cursor CURSOR FOR 
SELECT 
name FROM master.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb'
OPEN db_cursor   FETCH NEXT FROM db_cursor INTO @name  
WHILE @@FETCH_STATUS 0   BEGIN  
       SET 
@fileName @path @name '_' @fileDate '.BAK' 
       
BACKUP DATABASE @name TO DISK = @fileName 

       
FETCH NEXT FROM db_cursor INTO @name   END  

CLOSE 
db_cursor   DEALLOCATE db_cursor

Monday, February 27, 2012

Methods in Global.asax

Methods in Global.asax

This blog is intended to spread some light on the various methods which are available in global.asax file in ASP.NET. It’s very important to understand the methods in global.asax so that we as programmers can handle some application level events very efficiently. I said application level events and reason for using application word is that global.asax is an application level file and methods in it are used to handle application level events and these methods are not at all specific to any aspx page. Some of the common methods in the order in which they are executed are listed below
  • Application_Start
  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Session_Start
  • Application_EndRequest
  • Session_End
  • Application_End
  • Application_Error
Now let’s see what is the major difference between these methods or events. Oh I forgot to say, these are actually events not methods which get raised when a particular event gets triggered. Before we see the various methods in Global.asax I would like to tell you that Global.asax is actually derived from a class called “HttpApplication”. The above listed methods are only a few methods which I am gonna talk about. The listing of other methods can be found at the end of the blog. Now lets see the above mentioned events one by one.

Application_Start
Application_Start event gets triggered only once during the life cycle of the application. This once happens when the first request for any resource in the application comes. Resource can be a page or an image in the application. When the very first request for a resource, say a web page, is made by a user “Application_Start” is triggered after which this event is not at all executed. If by any chance the server where the application is hosted is restarted then this event is fired once again i.e. when the very first request for any resource in the application is made after the server is reset.

Application_BeginRequest
“Application_BeginRequest” is the second event which gets fired after “Application_Start”. Unlike the “Application_Start”, “Application_BeginRequest” is triggered for each and every request which comes to the application. Since this method is fired for any request made to the application you can use this method to keep track of what and all resources are accessed through this method.

Application_AuthenticateRequest
“Application_AuthenticateRequest” is the next event in line which is triggered after “Application_BeginRequest” is triggered. “Application_AuthenticateRequest” is also fired for each and every request. This event can be used to write code in scenarios where you want to do something when the user is getting authenticated.

Session_Start
The next event in line which gets triggered after “Application_AuthenticateRequest” is “Session_Start”. Session start event is fired only when a new session for a user starts. Once “Session_Start” for a user is fired then if the user makes subsequent request to any resource within the application this event is not at all triggered. The event is triggered only when the user’s session expires and then the user tries to access any resource in the application again.
This event can be used when you want to do something when the user visits you site/application for the first time or when his session starts. This event doesn’t get triggered if you are not using sessions which can be disabled in the web.config.

Application_EndRequest
The next event in line which gets fired once the request for the user is processed is “Applicatin_EndRequest”. This event is the closing event of “Applicatin_BeginRequest”. This event is also fired for each and every request which comes for the application.

Session_End
The closing event of “Session_Start” event. Whenever a user’s session in the application expires this event gets fired. So anything you want to do when the user’s session expires you can write codes here. The session expiration time can be set in web.config file. By default session time out is set to 20 mins.

Application_End
The same as “Application_Start”, “Application_End” is executed only once, when the application is unloaded. This event is the end event of “Application_Start”. This event is normally fired when the application is taken offline or when the server is stopped.

Application_Error
Now we come to the last event mentioned in this blog and that is “Application_Error”. This event gets fired when any unhandled exception/error occurs anywhere in the application. Any unhandled here means exception which are not caught using try catch block. Also if you have custom errors enabled in your application i.e. in web.config file then the configuration in web.config takes precedence and all errors will be directed to the file mentioned in the tag.
Lets see with an e.g. how these events get fired.
Suppose “A”, “B” and “C” are users who are going to access a site named “My Site”. “A” is the very first user to visit “My Site” and he/she is accessing “productlist.aspx” page. At this time the flow of the request is as follows. The “Application_Start” event is triggered, since “A” is the very first user to visit the application, after this “Application_BeginRequest”, then “Application_AuthenticateRequest”, then “Session_Start”, “productlist.aspx” page level events are processed and then “Application_EndRequest” event is triggered. After accessing “productlist.aspx” if “A” access some other page then for those page request the flow will be first “Application_BeginRequest”, “Application_AuthenticateRequest” then the page processing (page level events) and then “Application_EndRequest”. For every subsequent request this pattern is followed.

When “B” accesses some resource in the site, say “default.aspx”, then first “Applicatin_BeginRequest”, second “Application_AuthenticateRequest”, third “Session_Start” then “default.aspx” page level events are executed and after that “Application_EndRequest” is executed. After accessing “default.aspx” “B” access “productlist.aspx” then first “Application_BeginRequest”, second “Application_AuthenticateRequest” then “productlist.aspx” and then “Application_EndRequest” event is triggered. He refreshes the page the same events are executed in the same order.
The above same process is repeated for “C” also.
Suppose you have an unhandled exception and you don’t have custom errors enabled in web.config then when a user accesses a resource the flow will be first “Application_BeginRequest”, “Application_AuthenticateRequest”, page level event and an error occurs in the page then it goes to “Application_Error” after that “Application_EndRequest”.
The order mentioned above is how the events are triggered. So with this I hope you would have got a clear idea on how these events are triggered.
Some other events which are part of the HttpApplication class are as follows
  • PostAuthenticateRequest
  • AuthorizeRequest
  • PostAuthorizeRequest
  • ResolveRequestCache
  • PostResolveRequestCache
  • PostMapRequestHandler
  • AcquireRequestState
  • PostAcquireRequestState
  • PreRequestHandlerExecute
  • PostRequestHandlerExecute
  • ReleaseRequestState
  • PostReleaseRequestState
  • UpdateRequestCache
  • PostUpdateRequestCache
  • LogRequest. (Supported in IIS 7.0 only.)
  • PostLogRequest (Supported in IIS 7.0 only.)

Wednesday, January 11, 2012

Select some particular rows

SELECT UPPER(Name) FROM
(
   SELECT *, RN = row_number()
   OVER (ORDER BY Name)
   FROM Customer
   WHERE Name LIKE 'A%'
) A
WHERE RN BETWEEN 21 AND 30
ORDER BY Name