Microsoft SQL Server 2005 developer’s guide

Recently i started working on SQL Server 2005  development and developing applications using SQL Server 2005. Microsoft SQL Server 2005 Developer guide help me a lot and might be useful for others also. most importantly this book can use without any cost (web version). If you want a local then you should purchase a copy of this book.

Download Web Deployment Tool

The Web Deployment Tool is a tool for simplifying migration, management and deployment of Web applications, sites and servers. It can be used to package a Web site, automatically including content, configuration, certificates and databases. It can be used to synchronize between IIS 6.0 or IIS 7.0, or to migrate from IIS 6.0 to IIS 7.0. The packages created can be used for versioning, backup or deployment.

Features

Package your Web applications:

  • Packages a Web application or an entire site, including any associated databases.
  • Ability to package certificates, ACLs, COM, GAC and Registry settings.
  • Supports both live servers and zipped packages as a source or destination target Web applications.  
  • Seamless integration into the IIS 7.0 Manager and Visual Studio 10 interface.
  • Seamless integration into the Web Platform Installer for even simpler installations of community web applications.

Deploy your Web applications:

  • Administrative privileges are not required in order to deploy Web applications.
  • Ability to add powerful parameters to change text in files when they are deployed (such as prompting to replace a connection string when deploying from QA to staging environments).
  • Integration with the IIS 7.0 Web Management Service (WMSVC) for remote deployment by non-administrators.
  • Server administrators have granular control over the operations that can be performed and can delegate tasks to non-administrators.
  • In addition to the IIS Manager and Visual Studio 10, tasks can be performed using the command-line, PowerShell cmdlets or APIs. 

Synchronize your Servers:

  • Ability to synchronize or migrate the entire Web server, or a single Web site or application.
  • Synchronizes only data that has changed.
  • Ability to detect missing dependencies during synchronization.
  • Automatically gathers the following when you sync a Web site:
    • Content
    • IIS configuration
    • Certificates
    • Registry keys
    • ASP.NET configuration
  • Ability to use a secure service (authorized for server administrators only and can be secured with HTTPS, etc.) to synchronize the machines.

Download Web Deployment Tool – RC1 – x86.
Download Web Deployment Tool – RC1 – x64

An Overview of HTTP Handlers

An HTTP handler is a process that runs on server to response to a particular type of request. HTTP handlers can be referred to as endpoint also. A typical example of HTTP handlers is when ASP.net page handler which is used by asp.net engine to process the request that come for .aspx files.

Built In HTTP Handlers in ASP.net

Handler Description
ASP.net Page Handler (*.aspx) A default page handler for all ASP.net pages.
Web Service handler(*.mspx) The default HTTP handler for Web service pages created as .asmx files in ASP.NET.

Generic Web handler (*.ashx)

The default HTTP handler for all Web handlers that do not have a UI and that include the @ WebHandler directive.

Trace handler (trace.axd)

A handler that displays current page trace information. For details, see How to: View ASP.NET Trace Information with the Trace Viewer.

 

How to Create A Custom HTTP Handler

To create a custom HTTP Handler you need to implement either IHttpHandler or IHttpAsyncHandler for synchronous and asynchronous handlers. Both these interfaces expose two methods called IsReusable and ProcessRequest. ProcessRequest method is the place where you write code for handling request of your custom handler. The IsReusable property specifies whether the IHttpHandlerFactory object (the object that actually calls the appropriate handler) can put the handler in a pool and reuse it to increase performance. If the handler cannot be pooled, the factory must create a new instance of the handler every time that the handler is needed.

Public Class CustomHand
    Implements IHttpHandler

    Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
        Get

        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest

    End Sub
End Class

Mapping File Extension in IIS

By Default IIS is going to respond to file extension that is for custom handler. If you created a new file extension for HTTP Handler then you have to explicitly register the file extension in IIS and have to add a mapping entry in web.config file for your custom handler.

PHPAzure: PHP SDK for Azure

At the TechEd India Microsoft has announced PHP SDK for Azure. PHPAzure is an open source software development kit that allows PHP developers to build PHP applications for Azure platform. This SDK also Provides consistent programming model for Windows Azure Storage (Blobs, Tables & Queues).

PHPAzure Features:

  • PHP classes for Windows Azure Blobs, Tables & Queues (for CRUD operations)
  • Helper Classes for HTTP transport, AuthN/AuthZ, REST & Error Management
  • Manageability, Instrumentation & Logging support.
  • PHP SDK for Windows Azure is an open source collaboration project driven by RealDolmen and Microsoft.

    PHPAzure Architecture

    PHPAzure architecture

     

    Download PHPAzure SDK

    Silverlight Navigation : Browser Navigation Overview

    Silverlight does not provide built in direct navigation system not it provides integration with browser navigation system but Silverlight provide some other features that can be used for navigation while developing Silverlight applications. There is two type of navigation is possible in Silverlight application

    Browser Navigation

    Browser navigation means Silverlight application can directly point to pages that are outside of your application domain or applications. Like you can use browser navigation for redirecting user to some other web page. To enable user navigation to other web pages Silverlight provides a user control called HyperLinkButton and by setting it’s Navigateuri. There is one more important property HyperLinkButton has called TargetName means whether url will be opened in a new windows or in same window. It’s Content property is display the text of HyperLinkButton Control.

    <HyperlinkButton x:Name="hpb" Content=" All About ASP.Net" NavigateUri="http://allaboutasp.net" TargetName="_blank"></HyperlinkButton>

    The above example is simple static browser navigation example but browser navigation can also be done programmatically by manipulating HTML DOM objects through the HtmlPage class.

    <HyperlinkButton Content="Go to Silverlight Website" Click="GoToSilverlight" />
    Imports System.Windows.Browser
    
    Partial Public Class HomePage
        Inherits Page
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        'Executes when the user navigates to this page.
        Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
    
        End Sub
        Protected Sub GoToSilverlight(ByVal sendar As Object, ByVal e As System.Windows.RoutedEventArgs)
            If (HtmlPage.IsPopupWindowAllowed) Then
                HtmlPage.PopupWindow( _
                    New Uri("http://www.silverlight.net"), Nothing, Nothing)
            Else
                HtmlPage.Window.Navigate(New Uri("http://www.silverlight.net"))
            End If
    
        End Sub
    End Class
    

    Abstract class V/S Interface

    Abstract Class

    Abstract classes are classes that cannot be instantiated and are partially implemented or not implemented. Members that are implemented can still be overridden in the implementation class. A class can only inherit only one abstract class or any other type of class. Abstract classes provide elements of inheritance and interface.

    Interface

    Interfaces are definitions how a class needs to respond. An interface describes methods, properties (applicable to Visual Basic .Net) and events that a class needs to implement and type of parameters each member receive and return, but leaves the specific implementation of these members up to the implementing classes. A class may implement more then one interface.

    The choice of whether to design an abstract class or an interface sometimes can be difficult. Both interface and abstract class is useful for component integration. Some points that help you to whether to choose an abstract class or interface

    1. If you are creating multiple versions of component then use abstract class. By updating the base class all the inheriting classes are automatically updated with changes. Interfaces cannot be changed once they are created. If new version of interface is required, you must create a new version of interface.
    2. If the functionality you are creating will be useful across a wide range of disparate objects, use an interface.
    3. Abstract classes should be use for primarily for objects that are closely related whereas interfaces are used where common functionality is required to unrelated classes.
    4. If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
    5. If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members

    ASP.Net Exception Handling-Part I

    .Net languages support structured exception handling means when ever an exception occurs .Net framework creates an exception object, this exception object represents complete information about the exception. You can catch this exception object using the try catch block code if your application failed to catch the exception then you see a error page like this

    Exception Handling

    Structured Exception Handling Features

    • Exceptions are objects means each exception wrapped with significant amount of useful information about exception instead of just plain text explaining the exception message or cause of exception. These exception objects also support an InnerException property that allows you to wrap a generic error over the more specific error that caused it. You can even create and throw your own exception objects.
    • Exception can be caught based on their type means you can catch specific type of exception following code show an example of this
    Try
        IO.File.Open("F:\testfile.text", IO.FileMode.Open)
    
    Catch ex As IO.FileNotFoundException
        Console.WriteLine("File Not found")
    Catch ex As IO.PathTooLongException
        Console.WriteLine("File Path is to long")
    End Try

    • Exception handlers can also be used in layered manner means you can always create exception handlers on top of other exception handlers for different section of code to handle their exception separately.
    • Exceptions are generic part of .Net framework.

     

    Exception Class Overview

    Exception class is base class for all exception classes. Exception class defines two type of exceptions

    • SystemException: This class provides a means to differentiate exception caused by system or application. SystemException does not provide information about the cause of exception and try to avoid throwing instance of this class , if there are cases when you want to throw or created object of this class , a human readable message describing the error should be passed to the constructor.
    • ApplicationException: The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system. If you are creating your own exception class then it is always advised to derive custom exception class from Exception class. Deriving custom exception class from ApplicationException class does not add any significant value to derived class.

    Exception Class Properties

    Exception includes a number of properties that help identify the code location, the type, the help file, and the reason for the exception: StackTrace, InnerException, Message, HelpLink, HResult, Source, TargetSite, and Data.

    In Next article we will discuss more about exception class members and how to write a exception handling block.

    Silverlight Plug-in Lifecycle

    Silverlight Application class provides several services that commonly required by Silverlight application, so when you create a Silverlight you must create a class that is being derived from Silverlight Application class. Application class represents Entry point for your Silverlight application.

    Silverlight Plug-in Lifecycle

    Silverlight plug-in lifecycle starts with opening a web page that host a Silverlight plug-in. If Silverlight plug-in is not present then web page ask you to install Silverlight browser plug-in. Then web browser activates the Silverlight plug-in and start downloading application package. Silverlight plug-in load Silverlight core services, followed by Silverlight CLR (Common Language Runtime) which creates application domain for your application. After downloading application package CLR creates object of Application class and raise Application Startup event. Application constructor can also be used to initialize application task but generally its a good practice to use Application Startup event handler for most application initialization task.

    Silverlight Plug-in Lifecycle

    There can be only one Application instance in a Silverlight-based application. After startup, the Application instance provides several services that applications commonly require. You can access these services from any code in your application by retrieving the Application instance from the static Application.Current property.

    Silverlight Application Lifetime Management

    Silverlight Application class provides a number of features to developers and Application Lifetime management is one feature that is being offered by Silverlight Application class. You can add code to your application class that runs at the following points in the application lifetime:

    The application class constructor

    Application class constructor can be used for basic initialization of variables and attaching event handlers. Application class constructor typically includes a call to InitializeComponent method which is responsible for merging of XAML and code behind file. Generally your application classes are defined using XAML markup and a code-behind file.

    public Sub New()
        InitializeComponent()
    End Sub

    The application Startup event

    Silverlight plug-in raises Application Startup event after loading application package. At this point of time all application package assemblies are loaded and available for use. Application Startup event can be used for

    • Process data that you retrieve at startup, such as initialization and URL parameters, or data stored in a previous application session.
    • Display the application user interface (UI).
    • Begin asynchronous downloads of additional resource files or assemblies.
    Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
        Me.RootVisual = New MainPage()
    End Sub

    Application Exit

    The Application.Exit event occurs when one of the following actions takes place:

    • The user closes the Web page hosting the Silverlight plug-in.
    • The user refreshes the host Web page.
    • The user navigates the browser away from the host Web page.
    • The host Web page uses JavaScript and the HTML DOM to remove the plug-in from the page.
    • The user logs off or shuts down the operating system.

    One common use for the Application.Exit event is to save application settings by using the IsolatedStorageSettings class. For more information, see How to: Store and Retrieve Application Settings Using Isolated Storage.

    Private Sub Application_Exit(ByVal o As Object, ByVal e As EventArgs) Handles Me.Exit
    
    End Sub

    ASP.NET State Management Overview

    As HTTP is stateless, meaning the connection to the server does not remain open. When ever page is post back to server a new instance of the class is created this means there is a overhead of loading all the values associated with controls that are present on the page because http is a stateless protocol and each round trip to the server causes controls to loose their values. To overcome the inherent limitation of http protocol ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:

    View state

    View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings. This information is then put into the view-state hidden field or fields.

    Control state

    Control state is used to store the state information specific to control. This property is very useful when you are creating custom control and want to know the current state of control.  AS compare to view state property which can be turned off by developer at page level and that can cause your control to break, in case of control state property that can not be turned off like view state.

    Hidden fields

    Hidden fields are controls that provide a way to store information and at the same time they are not visible to the user. When a page is submitted to the server, the content of a hidden field is sent in the HTTP form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you want to store directly in the page. It is easy to see and modify the hidden field value so it is always recommend that never store sensitive information in Hidden field.

    Cookies

    Cookies are basically small text files that are used to store small amount of data on client file system. Cookies can also be stored in clients main memory. Cookies can be temporary (with specific expiration times and dates) or persistent. Generally cookies are used to store information about a particular client, session or application. When a client send a request to the server, browser also sent the cookie to the server, Server then extracts value from the cookie. Typically cookies are encrypted and used for storing user authentication information and user profile preferences.

    Response.Cookies("destination").Value = "CA"
    Response.Cookies("destination").Expires = DateTime.Now.AddDays(1)

    Query strings

    Query String is a key value pair that is appended at the end of url with a question mark (?). Query string is a very simple way to send information to the server but it is highly browser dependant. Different browsers have different length for query string. Information passed through query string is easily viewed by the client so query string is not a good option for sending sensitive information to the server.

    View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways.

    Application state

    Application state is a data repository available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions. Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another. Application state is stored in an instance of the HttpApplicationState class. This class exposes a key-value dictionary of objects. The HttpApplicationState instance is created the first time a user accesses any URL resource in an application. The HttpApplicationState class is most often accessed through the Application property of the HttpContext class.

    Application("WelcomeMessage") = "Welcome to the Contoso site."

    Session state

    ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.

    Session("FirstName") = FirstNameTextBox.Text
    Session("LastName") = LastNameTextBox.Text

    Profile Properties

    Profile property is a new feature in ASP.ne that allow you to store user specific data this some thing like session but profile information is not lost when a user session is expire. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the profile makes the user information available using a strongly typed API that you can access from anywhere in your application. You can store objects of any type in the profile. The ASP.NET profile feature provides a generic storage system that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.

    Profile.PostalCode = txtPostalCode.Text

    You must define the PostalCode property in the Web.config file by using the following markup:

    <profile>
        <properties>
          <add name="PostalCode" />
        </properties>
      </profile>

    Application state, Session state, and profile properties all store data in memory on the server.

    We will discuss each of the state management feature in more detail in upcoming articles. some of the definitions are taken from MSDN