Labels

Tuesday, December 15, 2009

SQL Server Cache Dependency - In easy words

Using the SQL Server Cache Dependency :

 

To utilize the new SQL Server Cache Dependency run setup of your SQL Server database using the aspnet_regsql.exe tool.

 

Found at C:\Windows\Microsoft.NET\Framework\v2.0xxxxx\. This tool makes the necessary

modifications to SQL Server so that you can start working with the new SQL cache invalidation features.

 

Follow these steps when using the new SQL Server Cache Dependency features:

 

1. Enable your database for SQL Cache Dependency support.

2. Enable a table or tables for SQL Cache Dependency support.

3. Include SQL connection string details in the ASP.NET application’s web.config.

4. Utilize the SQL Cache Dependency features in one of the following ways:

 

Ø  Programmatically create a SqlCacheDependency object in code.

Ø  Add a SqlDependency attribute to an OutputCache directive.

Ø  Add a SqlCacheDependency instance to the Response object via Response.AddCacheDependency.

 

This section explains all the steps required and the operations available to you.

 

See Below is the possible options.

 

Aspnet_regsql.exe -?

 

-d <Database Name>

 

-ed

Enable a database for SQL CacheDependency

-dd

Disable a database for SQL CacheDependency

-et

Enable a table for SQL CacheDependency

-dt

Disable a table for SQL CacheDependency

-t <Table Name>

 

-lt

List all the tables enabled for SQL CacheDependency

 

Step 1: Enabling Databases for SQL Server Cache Invalidation

 

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 > aspnet_regsql -C "Data Source=localhost;Integrated Security=True; Initial Catalog=Northwind" -ed

 

Step 2: Enabling Tables for SQL Server Cache Invalidation

 

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 > aspnet_regsql -C "Data Source=localhost;Integrated Security=True; Initial Catalog=Northwind"  -et -t Categories

 

Step 3: Include SQL connection string details in the ASP.NET application’s web.config

 

<configuration>

<connectionStrings>

<add name="Northwind" connectionString="data source=XIPL0060;initial catalog=Northwind; user id=sa;password=sa;persist security info=True;packet size=4096"/>

</connectionStrings>

<system.web>

    <caching>

      <sqlCacheDependency enabled="true" pollTime="5000">

        <databases>

          <add  name="Northwind"  connectionStringName="Northwind" />

        </databases>

      </sqlCacheDependency>

    </caching>

</system.web>

</configuration>

 

Name

Provides an identifier to the SQL Server DB

Connectionstringname

Connection String Name

pollTime

Not required for SQL Server 2005

Spedifies time intrerval to poll.

 

 

Before we start with 4th step, lets take a look at few other things.

 

Looking at SQL Server :

 

As the Northwind database and the Customers and Products tables have all been enabled

for SQL cache invalidation, look at what has happened in SQL Server. You’ll see a new table contained within the Northwind database— AspNet_SqlCacheTablesForChangeNotification

 

This is the table that ASP.NET uses to learn which tables are being monitored for change notification and also to make note of any changes to the tables being monitored. The table has three columns

 

Ø  tableName : Contains names of the tables enabled for SQL cache invalidation.

Ø  notificationCreated : shows the date and time when the table was enabled for SQL cache invalidation.

Ø  changeId : Used to communicate to ASP.NET any changes to the included tables. ASP.NET monitors this column for changes and, depending on the value, either uses what is stored in memory or makes a new database query.

 

ASP.NET makes a separate SQL Server request on a completely different thread to the AspNet_SqlCacheTablesForChangeNotification table to see if the changeId number has been incremented. If the number is changed, ASP.NET knows that an underlying change has been made to the SQL Server table and that a new result set should be retrieved. When it checks to see if it should make a SQL Server call, the request to the small AspNet_SqlCacheTablesForChangeNotification table has a single result. With SQL Server cache invalidation enabled, this is done so quickly that you

really notice the difference.

 

 

Looking at the Tables That Are Enabled :

 

To get a list of the tables that are enabled, use something similar to the following command:

aspnet_regsql.exe -S localhost -U sa -P password -d Northwind –lt

 

Disabling a Table for SQL Server Cache Invalidation:

aspnet_regsql.exe -S localhost -U sa -P password -d Northwind -t Products –dt

 

Disabling a Table for SQL Server Cache Invalidation:

aspnet_regsql -S localhost -U sa -P wrox -d Northwind –dd

 

 

Note: That disabling an entire database for SQL Server cache invalidation also means that every single

table contained within this database is also disabled.

 

If you now open the Northwind database in the SQL Server Enterprise Manager, you can see that the

AspNet_SqlCacheTablesForChangeNotification table has been removed for the database.

 

Step 4: Utilizing the SQL Cache Dependency features in one of the following ways

 

Now that the web.config file is set up and ready to go, the next step is to actually apply these new

capabilities to a page.

 

Ø  Programmatically create a SqlCacheDependency object in code.

Ø  Add a SqlDependency attribute to an OutputCache directive.

Ø  Add a SqlCacheDependency instance to the Response object via Response.AddCacheDependency.

 

Using Programmatically :

 

<%@ Page Language=”C#” %>

<%@ Import Namespace=”System.Data” %>

<%@ Import Namespace=”System.Data.SqlClient” %>

 

<script runat=”server”>

protected void Page_Load(object sender, System.EventArgs e)

{

DataSet myCustomers;

myCustomers = (DataSet)Cache[“firmCustomers”];

if (myCustomers == null)

{

SqlConnection conn = new SqlConnection(

ConfigurationManager.ConnectionStrings[“AppConnectionString1”].ConnectionString);

SqlDataAdapter da = new SqlDataAdapter(“Select * from Customers”, conn);

myCustomers = new DataSet();

da.Fill(myCustomers);

 

if (!SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString).Contains("CUSTOMERS "))

                                     SqlCacheDependencyAdmin.EnableTableForNotifications(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString, " CUSTOMERS ");

SqlCacheDependency myDependency = new SqlCacheDependency(“Northwind”, “Customers”);

Cache.Insert(“firmCustomers”, myCustomers, myDependency);

 

Label1.Text = “Produced from database.”;

}

else

{

Label1.Text = “Produced from Cache object.”;

}

 

GridView1.DataSource = myCustomers;

GridView1.DataBind();

}

</script>

 

The Complete Syntax is as below:

 

Cache.Insert(key As String, value As Object,

dependencies As System.Web.Caching.CacheDependency

absoluteExpiration As Date, slidingExpiration As System.TimeSpan)

priority As System.Web.Caching.CacheItemPriority,

onRemoveCallback As System.Web.Caching.CacheItemRemovedCallback)


 

Using OutputCache :

 

<%@ Page Language=”VB” %>

<%@ OutputCache Duration=”3600” VaryByParam=”none” SqlDependency=”Northwind:Customers”%>

 

<script runat=”server”>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Label1.Text = “Page created at “ & DateTime.Now.ToShortTimeString ()

End Sub

</script>

 

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head runat=”server”>

<title>Sql Cache Invalidation</title>

</head>

<body>

 

<form id=”form1” runat=”server”>

<asp:Label ID=”Label1” Runat=”server”></asp:Label><br />

<br />

<asp:GridView ID=”GridView1” Runat=”server” DataSourceID=”SqlDataSource1”></asp:GridView>

 

<asp:SqlDataSource ID=”SqlDataSource1” Runat=”server”

SelectCommand=”Select * From Customers”

ConnectionString=”<%$ ConnectionStrings:AppConnectionString1 %>”

ProviderName=”<%$ ConnectionStrings:AppConnectionString1.providername %>”>

</asp:SqlDataSource>

</form>

</body>

</html>

 

 

To add more than one table, you use the OutputCache directive shown here:

SqlDependency=”database:table;database:table”

 

 

Using Request Object :

 

SqlCacheDependency myDependency = new SqlCacheDependency(“Northwind”, “Customers”);

 

Response.AddCacheDependency(myDependency);

Response.Cache.SetValidUntilExpires(true);

Response.Cache.SetExpires(DateTime.Now.AddMinutes(60));

Response.Cache.SetCacheability(HttpCacheability.Public);

 

 

The SqlCacheDependency class takes the following parameters:

SqlCacheDependency(databaseEntryName As String, tablename As String)

 

You use this parameter construction if you are working with SQL Server 7.0 or with SQL Server 2000. If

you are working with SQL Server 2005 you use the following construction:

SqlCacheDependency(sqlCmd As System.Data.SqlClient.SqlCommand)

 

Hope this helps.

 

Regards,

Arun

 

 

 

Monday, December 14, 2009

Stored Procedure Practices

Stored Procedure Practices:

 

  • Do not use Case statements in where clauses, they are a performance nightmare and hard for SQL to optimize.
  • You shouldn’t put IF statements that run different queries in a SP as the query optimizer will only optimize the branch that gets executed the first time.  When you take the alternate branch, you will have table scans for everything.
    • To get around this somewhat by having SP_WITH_RECOMPILE which will force a recompile each time – better solution is to split into separate SPs that can each be optimized and have the main SP call into the right one based on a simple/fast IF
  • Any hidden IO in the functions, should be unwound out of the function and put in the main query instead
  • As a general philosophy, from what we’ve seen in the database coding {or lack thereof in understanding how the query optimizer works in general} they should just be retrieving data from the database and the middle-tier or client should be doing all this display formatting.
  • A lot of function calls in the SPs should be unwound – again perhaps refactoring to the middle tier as opposed to putting function calls to outside C# .dlls in where clauses – you will see a cleaner code base and better options for performance enhancements.

 

Regards,

Arun

Friday, December 11, 2009

WWF vs BizTalk

Introduction

When I started studying Windows Workflow Foundation (WF), I was confused with the fact that there are lots of similarities between WF and BizTalk Server. Then I did some more studies and got hold of some good posts from Microsoft regarding the comparison of WF and BizTalk Server. Let me share what I summed up.

 

Windows Workflow Foundation

Windows Workflow Foundation (WF) is a programming model, set of tools, and runtime environment that allows one to write declarative workflows on the Windows platform to represent the execution model of your programs. The WF runtime is part of the .NET Framework, first appearing in .NET Framework 3.0, with improvements in .NET Framework 3.5.

 

Microsoft BizTalk Server

Microsoft BizTalk Server provides an efficient and effective way to integrate systems and businesses through manageable business processes, enabling them to automate and orchestrate interactions in a highly flexible and highly automated manner.


Microsoft BizTalk Server provides a development and run-time environment for business process management (BPM) and automation.

 

Fundamental Difference between WF and BizTalk Server

 

WF and BizTalk are not competing technologies. Windows Workflow Foundation and BizTalk are complementary technologies that serve different needs.

 

Windows Workflow Foundation

BizTalk Server

WF is a developer framework used to implement workflow inside an application.

BizTalk Server is a product that can be used to implement workflow across disparate applications.

WF is a framework that provides the building blocks needed to build workflow-based applications.

BizTalk is an integration server that includes the ability to add business process automation.

WF is a framework that provides developers with the base components they need to build the modules that will be used to automate processes.

BizTalk Server is a platform that provides developers with the pieces they need to automate business process.

WF does not have the inherent features or tools for tracking, administration and so on that is available with BizTalk.

BizTalk provides a lot of capabilities that are needed for serious business process automation that WF developers would have to write. To name a few, BizTalk has proven scalability, tracking, administration and transformation capabilities that a WF developer would need to write from scratch.

 

Comparison between WF and BizTalk Server

 

The following table shows the feature comparison between WF and BizTalk Server:

 

Feature

Windows Workflow Foundation

BizTalk Server

Hosting

Hosted in a custom application (client-side execution, but the client could be an ASP.NET application)

Server-side in the BizTalk process

Designer

Included in Visual Studio, or custom designers can be written

Included in Visual Studio

Scalability

Developer must implement

Well-proven, highly scalable

Transactional integrity

Developer must implement

Long running and atomic (ACID) transactions

Tracking infrastructure

Simple framework pieces provided that allow you to build the tracking infrastructure

Comprehensive Business Activity Monitoring infrastructure provided

Runtime modification of “in-flight” workflows

Yes, but developer must implement

No, workflows are defined at design time

Cross-platform integration capabilities

Not supported natively

Extensive adapters available

Composability

WF processes cannot directly invoke a BizTalk application, although you could indirectly by calling an orchestration that had been exposed as a Web service (for example), or perhaps by API usage

A BizTalk process could invoke a WF process via Web service call, or from a helper class or expression shape

Management and administration

Developer must implement

Extensive set of tools provided for IT pros to administer and track execution

Windows Communications Framework (formerly “Indigo”) support

Natively supported

Through an adapter, or could be called from an expression shape or helper class

Rules engine support

Yes

Yes

Extensible activities

Yes

No

Transformation capabilities

No

Yes

Programmability

WF is a framework. You must implement applications to use it.

BizTalk Server exposes APIs for most parts, and has numerous extensibility points such as pipeline components, adapters and “functoids” (out-of-the box and custom mapper components)

 

 

Friday, December 4, 2009

Microsoft Versions

Versions

Date  

Version

Remarks  

New ASP.NET related features 

January 16, 2002

(Time when joined CMC)

1.0

First version released together with Visual Studio .NET

  • Object oriented web application development supporting Inheritance, Polymorphism and other standard OOP features
    • Developers are no longer forced to use Server.CreateObject(...), so early-binding and type safety are possible.
  • Based on Windows programming; the developer can make use of DLL class libraries and other features of the web server to build more robust applications that do more than simply rendering HTML (i.e. exception handling)

 

April 24, 2003

1.1

Released together with Windows Server 2003

Released together with Visual Studio .NET 2003

 

  • Mobile controls
  • Automatic input validation

November 7, 2005

(Before Start of CCH)

2.0

Codename Whidbey released together with Visual Studio 2005 and

Visual Web Developer Express and

SQL Server 2005

  • New data controls (GridView, FormView, DetailsView)
  • New technique for declarative data access (SqlDataSource, ObjectDataSource, XmlDataSource controls)
  • Navigation controls
  • Master pages
  • Login controls
  • Themes
  • Skins
  • Web parts
  • Personalization services
  • Full pre-compilation
  • New localization technique
  • Support for 64-bit processors
  • Provider class model

 

November 21, 2006

(Time when about to leave Rishabh)

 

3.0

 

 

November 19, 2007

(Monetrix - Start)

3.5

Released with Visual Studio 2008 and Windows Server 2008

  • New data controls (ListView, DataPager)
  • ASP.NET AJAX included as part of the framework
  • Support for HTTP pipelining and syndication feeds.
  • WCF Support for RSS, JSON, POX and Partial Trust

 

August 11, 2008

(Monetrix – Finishing stage)

3.5 Service Pack 1

Released with Visual Studio 2008 Service Pack 1

  • Incorporation of ASP.NET Dynamic Data
  • Support for controlling browser history in an ASP.NET AJAX application
  • Capability to combine multiple Javascript files into a single file for more efficient downloading
  • New namespaces System.Web.Abstraction and System.Web.Routing

 

 

Reference: Link

 

Regards,

Arun

 

 

 

 

 

Tuesday, December 1, 2009

WS* Specifications & WSE

Hi,

 

We’ll go step by step.

 

  1. What are WS* Specifications
  2. What are WSE Enhancements

 

WS* Specifications

 

  • There are a variety of specifications associated with web services. These Web service specifications are occasionally referred to collectively as "WS-*". The reference term "WS-*" is more of a general nod to the fact that many specifications are named with "WS" as their prefix
  • These specifications are in varying degrees of maturity and are maintained or supported by various standards bodies and entities.
  • Specifications may complement, overlap, and compete with each other.

 

The specifications lie under different heads.

 

  1. Web Service Standards Listings
  2. XML Specifications
  3. Messaging Specifications
  4. Metadata Exchange Specifications
  5. Security Specifications
  6. Privacy
  7. Reliable Messaging Specifications
  8. Resource Specifications
  9. Web Services Interoperability organization (WS-I) Specifications
  10. Business Process Specifications
  11. Transaction Specifications
  12. Management Specifications
  13. Presentation Orientated Specification
  14. Draft Specifications

 

Here are the details on each.

 

Web Service Standards Listings

These sites contain documents and links about the different Web Services standards identified on this page.

 

    * IBM's Web Services Standards Page

    * Microsoft's Web Services Standards Page

    * World Wide Web Consortium's Web Services Activity

    * innoQ's WS-Standards Poster

    * OASIS Standards and Other Approved Work

    * XML CoverPages

    * Open Grid Forum Final Documents

 

XML Specifications

    * XML (eXtensible Markup Language)

    * XML Namespaces

    * XML Schema

    * XPath

    * XQuery

    * XML Information Set

    * XInclude

    * XML Pointer

 

Messaging Specifications

    * SOAP (formerly known as Simple Object Access Protocol)

    * SOAP Message Transmission Optimization Mechanism

    * WS-Notification

          o WS-BaseNotification

          o WS-Topics

          o WS-BrokeredNotification

    * WS-SoapOverUDP

    * WS-Addressing

    * WS-Transfer

    * WS-Eventing

    * WS-Enumeration

    * WS-MakeConnection

 

Metadata Exchange Specifications

    * WS-Policy

    * WS-PolicyAssertions

    * WS-PolicyAttachment

    * WS-Discovery

          o WS-Inspection

    * WS-MetadataExchange

    * Universal Description, Discovery, and Integration (UDDI)

    * WSDL 2.0 Core

    * WSDL 2.0 SOAP Binding

          o Web Services Semantics (WSDL-S)

    * WS-Resource Framework (WSRF)

 

Security Specifications

    * WS-Security

    * XML Signature

    * XML Encryption

    * XML Key Management (XKMS)

    * WS-SecureConversation

    * WS-SecurityPolicy

    * WS-Trust

    * WS-Federation

    * WS-Federation Active Requestor Profile

    * WS-Federation Passive Requestor Profile

    * Web Services Security Kerberos Binding

    * Web Single Sign-On Interoperability Profile

    * Web Single Sign-On Metadata Exchange Protocol

    * Security Assertion Markup Language (SAML)

    * XACML

 

Privacy

  • P3P

 

Reliable Messaging Specifications

    * WS-ReliableMessaging

    * WS-Reliability

    * WS-RM Policy Assertion

 

Resource Specifications

    * Web Services Resource Framework

    * WS-BaseFaults

    * WS-ServiceGroup

    * WS-ResourceProperties

    * WS-ResourceLifetime

    * WS-Transfer

    * Resource Representation SOAP Header Block

 

Web Services Interoperability organization (WS-I) Specifications

These specifications provide additional information to improve interoperability between vendor implementations.

 

    * WS-I Basic Profile

    * WS-I Basic Security Profile

    * Simple Soap Binding Profile

 

Business Process Specifications

    * WS-BPEL

    * WS-CDL

    * Web Services Choreography Interface

    * WS-Choreography

    * XML Process Definition Language

 

Transaction Specifications

    * WS-BusinessActivity

    * WS-AtomicTransaction

    * WS-Coordination

    * WS-CAF

    * WS-Transaction

    * WS-Context

    * WS-CF

    * WS-TXM

 

Management Specifications

    * WS-Management

    * WS-Management Catalog

    * WS-ResourceTransfer

    * WSDM

 

Presentation Orientated Specification

Web Services for Remote Portlets

 

Draft Specifications

WS-Provisioning Describes the APIs and Schemas necessary to facilitate interoperability between provisioning systems in a consistent manner using Web services

 

 

 

WSE Enhancements

 

  • WSE is an add-on to the Web Services, and enables to implement the above mentioned WS-* Web service specifications -  but chiefly in areas such as Security, Reliable Messaging, and Sending Attachments.
  • WSE provides extensions to the SOAP protocol i.e. SOAP protocol extensions and allows the definition of custom security, reliable messaging, policy, etc.
  • Developers can add these capabilities at design time using code or at deployment time through the use of a policy file.

 

There are multiple versions of WSE.

 

WSE 1.0

 

  • For .NET Framework 1.0 was released in December 2002.
  • It was based on the draft version of WS-Security.
  • It is not supported anymore and is not compatible with .NET 2.0.
  • It uses the older "XMLSOAP" namespace in contrast to the OASIS namespace used by WSS4J and WSE 2.0/3.0.

 

 

WSE 2.0

 

  • Released for Visual Studio .NET 2003 and the .NET Framework 1.1 in May 2004.
  • It introduced major secure communication improvements (signing and encryption of user-defined SOAP headers, Kerberos Security Context Tokens, delegated trust etc), a new lightweight messaging infrastructure, a new programming model, support for SOAP based messaging over TCP as an alternative to HTTP, a policy framework based on WS-Policy and WSDL, WS-Addressing, WS-Trust, WS-SecureConversation support.
  • WSE 2.0 can be used from within standalone executables and Windows services i.e. outside IIS in addition to ASP.NET applications.
  • It is also compatibile with .NET 2.0, however it does not have design time support with Visual Studio 2005.
  • It is not interoperable with WSE 3.0 and WCF.

 

WSE 3.0

 

·         Released in October 2005 and has design time support with Visual Studio 2005.

·         It includes policy framework enhancements including security based on policy assertions (associating CLR client proxies with policy files), turnkey security scenarios for securing end to end messages, extensibility mechanisms for user-defined policies in code and a simplified policy model applied to a message exchange instead of on a per-message level.

·         It supports updated Web services specifications and a native 64-bit runtime. WS-SecureConversation sessions can be cancelled explicitly and sessions are reliable and usable in web farm scenarios as Security Context Tokens can contain the original client authentication token when sent from the client to the service, which enable sessions to be re-established if lost, e.g. when a service's appdomain is reset.

·         WSE 3.0 is wire-level interoperable over HTTP with WCF and supports the same version of the WS-* specifications as WCF (WS-Security 1.1, SOAP 1.2, MTOM).

 

 

Note: It seems that there is no WSE 4.0 to work with VS2008. Instead, VS 2008 relies on WCF for the same functionality.

 

 

Hope this helps.

 

Reference: WS* Specifications, WSE

 

 

Regards,

Arun Manglick