Spinning the Web

"Will you walk into my parlour?"
Said the spider to the fly;
"'Tis the prettiest little parlour
That ever you did spy.
The way into my parlour
Is up a winding stair;
And I have many curious things
To show you when you're there."

Friday, August 03, 2007

SQL 2005 Common Table Expressions

Common Table Expressions is a newly introduced feature in SQL Server 2005. It is similar to a temp table or a view, but its scope is limited to a single SELECT statement.

Syntax

A CTE is made up of

1. CTE name

2. An optional column list

3. A query defining the CTE

The basic syntax structure for a CTE is:

WITH CTE_name [ ( column_name [,...n] ) ]
AS
(
CTE_query_definition
)

The statement to use the CTE is:

SELECT
FROM CTE_name

Note: The query using the CTE must be the first query appearing after the CTE.

Example

WITH PriceList_CTE( ProductName, ListPrice, DiscountPrice) AS
(
SELECT [Name] AS ProductName, ListPrice, ListPrice * .95
FROM Production.Product
)

SELECT ProductName, ListPrice, DiscountPrice
FROM PriceList_CTE

Recursive CTEs

Used for easily traversing heirarchical data structures. Eg: Displaying employees in an organizational chart.

A recursive CTE consists of three elements:

1. Initial sub-query

The seed value.

2. Recursive sub-query

The recursive portion contains a reference to the rows added during the previous iteration.

3. Termination check

Recursion stops automatically whenever an iteration generates no new rows. The final resultset is the union of all result sets generated by the anchor and recursive members.

Syntax

WITH CTE_name ( column_name [,...n] )
AS
(
CTE_query_definition –- Anchor member

UNION ALL

CTE_query_definition –- Recursive member
)

Labels: ,

Friday, June 22, 2007

Dynamic web service reference path

Our team ran into a problem recently in ASP.NET. We're using a web service in our web application for data access. The web reference was added to a class library project in our Visual Studio 2005 solution. (We use the WAP - Web Application Project - model) . Simply right clicking on the project name in solution explorer and choose 'Add web reference' from the context menu. Everything was working perfectly fine.

The problems started when we tried deploying the application to a test server prior to going live with it. The web service was no longer being referenced properly. We racked our brains for a couple of hours trying to find a solution for this. We had a close look at the class library in which the web service was being referenced and found that the web service path was being saved as a setting in a .config file named app.config. The app.config contained the following XML mark-up:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configsections>
<sectiongroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="ACME.Services.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirepermission="false">
</section>
</sectiongroup>
<applicationsettings>
<ACME.Services.Properties.Settings>
<setting name="ACME_Services_ACMEWebService_ACMEWebService" serializeas="String">
<value>http://ACME/WebServices/ACMEWebService.asmx</value>
</setting>
</ACME.Services.Properties.Settings>
</applicationsettings>
</configsections>

The web reference URL was being read from this config file. But since it was in a class library, the whole thing was getting complied into a DLL on deployment.

The workaround we found for this was:

1. copy the section handler (the mark-up inside <sectiongroup>...</sectiongroup> into the <configsections> node in the applications Web.config

2. copy the <applicationsettings>...</applicationsettings> section also into the Web.config.

And Voila! Now since this is part of the web.config, it won't be compiled any more. On deployment, just change the web service path setting (inside <value>...</value>) to the new path. Cool, right?

Labels: , ,

Friday, July 21, 2006

Good links to resources on .NET

Here are some links to resources on ASP.NET 2.0

User-Controls

http://www.asp.net/QuickStart/aspnet/doc/ctrlref/userctrl/default.aspx
http://blogs.meetandplay.com/WTilton/archive/2005/12/08/613.aspx http://dotnet.sys-con.com/read/171169.htm - [ Creating Composite Server Controls ]

URL Rewriting With Regular Expressions

http://pietschsoft.com/blog/post.aspx?postid=762

Custom Paging in ASP.NET 2.0 with SQL Server 2005

http://aspnet.4guysfromrolla.com/articles/031506-1.aspx http://aspnet.4guysfromrolla.com/articles/032206-1.aspx - [ Sorting ]

Caching

http://www.15seconds.com/issue/040518.htm

Master Pages

http://www.devsource.com/article2/0,1895,1928568,00.asp http://www.devsource.com/article2/0,1759,1824218,00.asp
http://www.devsource.com/article2/0,1759,1849989,00.asp
http://www.devsource.com/article2/0,1759,1945460,00.asp - [ Using Client Callback ] http://www.devsource.com/article2/0,1759,1856089,00.asp

Cross-page Postbacks

http://www.developerfusion.co.uk/show/4687/
http://www.odetocode.com/Articles/421.aspx - [ Design Considerations ]

Labels: , ,