Caveman's Blog

My commitment to learning.

Archive for June, 2009

.NET Framework

Posted by cavemansblog on June 28, 2009

The following illustration shows the relationship of the common language runtime and the class library to your applications and to the overall system. The illustration also shows how managed code operates within a larger architecture.

Dotnet

Points of interest

1. The common language runtime manages memory, thread execution, code execution, code safety verification, compilation, and other system services. These features are intrinsic to the managed code that runs on the common language runtime.

2. The .NET Framework class library is a collection of reusable types that tightly integrate with the common language runtime. The class library is object oriented, providing types from which your own managed code can derive functionality. This not only makes the .NET Framework types easy to use, but also reduces the time associated with learning new features of the .NET Framework. In addition, third-party components can integrate seamlessly with classes in the .NET Framework.

Note: This article in its entirety has been borrowed from certain parts of [1]. I did not want to spoil the essence of the original article.

References:
1. .NET Framework Conceptual Overview

Posted in Dotnet, Sudheer Reddy Battula | Tagged: | 1 Comment »

SQL Server: Export data to Excel

Posted by cavemansblog on June 22, 2009

This article will demonstrate one of the several ways of exporting data from SQL Server 2005 to an Excel spread sheet. This time we will use simple SQL queries to export data unlike the earlier instance when we used SSIS. The precursor to achieving this will be to perform a onetime operation via, enabling the running of Ad Hoc Distributed Queries on your SQL Server. This can be accomplished by using the SQL Server 2005 Surface Area Configuration Utility or by executing the following code in SQL Server Management Studio’s Query Editor:

sp_configure 'show advanced options', 1
GO
reconfigure
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
reconfigure

When the server is capable of running Ad Hoc Distributed Queries we are all set to run SQL queries to export data to Excel spreadsheet. It must kept in mind that an Excel template with all the intended columns has to exit before data can be exported and the file must be closed while data is transferred. In the following example data from the “employee” table in the SQL Server 2005 database is being exported to an Excel spreadsheet named “EMP”.

--Export data to Excel
insert into openrowset('Microsoft.Jet.OLEDB.4.0' ,
'Excel 8.0;Database=c:\test\test.xls','Select * from [EMP$]')
select empid, ename from employee

References:
1. Server Settings Configuration Options

Posted in Sql Server, Sudheer Reddy Battula | Tagged: , , | 1 Comment »

Free Screen Capture Utilities

Posted by cavemansblog on June 19, 2009

Moi only knows how many times I would have wished that I owned a copy of Snag-It [3], a screen capture tool. This is one of the most awesomest screen capture aid available in the market. It even supports the capturing of a multi-page screen shot. This tool is easy to use, has a bundle of exciting features and the interface is very sleek. I know that not everything is life is free; meaning to say some are infact free and here is a list of a free alternatives:

Cropper [1] is a screen capture application written in C# on the Microsoft .Net platform. It makes it fast and easy to grab parts of your screen. Use it to easily crop out sections of vector graphic files such as Fireworks without having to flatten the files or open in a new editor. Use it to easily capture parts of a web site, including text and images. Cropper can save the screen capture to the clipboard, have it sent directly to the printer, or automatically save it to disk as a BMP, PNG, or JPG file. The nice set of features in this app makes it my favorite free screen capture aid.

Cropper

Tebo Screen [2] is a simple screen capture utility developed by Guy Thiebaut [2]. It is another C# .Net application that has three buttons; Capture Screen: To capture the entire screen, Capture Area: holding down the left mouse button, users draw a rectangle specifying which part of the screen they wish to capture. On releasing the left mouse button, the user selects a file name and the area behind the drawn rectangle is captured to this file. Exit: obviously, to exit the application. I like the simplicity of the code and is an excellent source for beginners to understand how this is done programatically. BMP is the default image saving format, the code can be tweaked very easily to save the image in other formats like .jpg, .gif, etc.

Tebo Screen

ZScreen [4] is another C# .Net 3.5 utility for the same purpose. I am yet to try this and will post about this soon.

FireShot [5] is an add-on for the Firefox and IE browsers that can be used to capture entire or part of a web page. This comes with an editor that is handy to manipulate the screen capture. Screen shots can be saved in one of these formats: PNG, GIF, JPEG and BMP. Check here to download Firebox add-on and here to downloadIE add-on.

References:
1. Cropper by Brian Scott
2. Tebo Screen by GuyThiebaut
3. Snag-It from Tech Smith Corporation.
4. ZScreen by Zachary Hudock.
5. FireShot

Posted in Tools | Tagged: , | 3 Comments »

Sql Server: Union vs Union All

Posted by cavemansblog on June 13, 2009

This post is to showcase the subtle yet important difference between the usage of Union and Union All in SQL.The output of query when Union of two or more select statements returns the distinct rows returned by all the select queries, where as when the Union All is used, all the rows returned by each select query will be in the grand output.

Let me demonstrate with an example:

declare @table1 Table(Id int identity(1,1), name varchar(50))
declare @table2 Table(Id int identity(1,1), name varchar(50))

--Insert dummy date into table 1
Insert @table1(name) values('test 1')
Insert @table1(name) values('test 2')
Insert @table1(name) values('test 3')

--Insert dummy date into table 2
Insert @table2(name) values('test 1')
Insert @table2(name) values('test 2')
Insert @table2(name) values('test 3')

--UNION: returns 3 rows
select * from @table1
union
select * from @table2

--UNION ALL: returns 6 rows
select * from @table1
union all
select * from @table2

and here is the output:

union

Posted in Sql Server, Sudheer Reddy Battula | Tagged: , | Leave a Comment »

Load balancing a web application

Posted by cavemansblog on June 12, 2009

Load Balancing (LB) is the technique of trying to achieve an even distribution of a given load between the load bearers of a system. The goal in LB is to achieve scalability of the system with increasing load, thus improving the performance of the system as a whole. The most common use of this technique is in areas such as: Telecommunications, Web Servers, Database Servers, Avionics, Shipping Industry and Power Grids to name a few.

Introduction

When a user on a computer uses a browser to request a web page from a web server, the browser makes a call to the DNS Server to determine the IP address of the webserver, followed by the browser making a connection to the  webserver using that IP address to establish a connection for request of information. As web server receives many such requests, resulting in the increase of the load/traffic at the webserver. Boosting the server capabilities via adding more RAM and more computational power will be the first order of implementation for improving the server performance(response time). This kind of scaling is limited and alternate methods of improving performance came into existence.

DNS [2] round robin is a model that was one of the early strategies employed for load balancing web servers. This mechanism was based on the fact that several IP addresses can be assigned to one host name, meaning to say the web server traffic can be distributed between multiple IP addresses (computers). Caching of IP addresses by the DNS servers can lead to traffic distribution limitations in the DNS round robin. Lets say when a cached IP addressed computer goes down, this load distribution solution becomes ineffective. At that point the DNS server doest not know how to route the request.  This short coming has lead to the evolution another effective and scalable solution via Server Load Balancing (SLB). Server load balancing is important especially because of the unpredictable nature of the web traffic (number of requests).

Server Load Balancing (SLB)

High availability and scalability is the most important criteria to be kept in mind when designing a Enterprise (Web) Application solution. Fortunately SLB is able to provide scalability and availability to cater to the needs of ever increasing server load. Typically multiple web servers are employed to host a website so that load can be distributed evenly when one server gets swamped. A web farm environment is like one large virtual computer where the load balancer acts as a controller that knows which processing unit (web server) has to be delegated a pending client web request and then promptly sends web responses to that client. This environment is multi-server scenario where we may have a server in each state of US for example. Then when the load on one server is in excess of the configured capacity, the other servers step in to bear the brunt.

LoadBalancer

How a load balancer bears the load it is based on various models listed below:
1. RoundRobin. (All servers share load equally)
2. NLB (economical)
3. HLB (expensive but can scale up to 8192 servers)
4. Hybrid (of 2 and 3).
5. CLB (Component load balancer).

State Management

One of the shortcomings of HTTP is that it is stateless protocol. It works in a disconnected fashion, meaning to say the once the server processes and send a response to a client, the web server does not retain the identity of the client. Hence the necessity for a mechanism that can keep track of the client’s identity and the client specific data, called also as State. Implementing the most suitable mechanism of state management is one of the most challenging part while setting up a web farm. State can be stored in this environment at one or more of the following three places:

1. State Server – single point of failure
2. Database. – additional overhead in processing the web request
3. Web Server – unreliable because of load balancing

I personally like a hybrid approach where the session is stored both in the database and the web server. This is why this might be prudent approach; when a request is processed, the web server first checks its own cache for the session state information, if it is not found it will hit the database to re-establish the state for that request. This way you get the best of both worlds via saving the session very reliably and being able to access it in very fast and efficient manner. Any changes to the state during the processing of a request will be persisted to the database. Ofcourse, storing the encrypted session id in a cookie is necessary to identify the state between round trips to the web server by the client activity.

Note: A web garden is different from a web farm in the sense that, a web garden is a multi-processor setup. i.e., a single server (not like the multi server above).

References:

1. Wikipedia – Load Balancing
2. Domain Name Server – DNS

Posted in Infrastructure, Sudheer Reddy Battula, Web Applications | Tagged: , , , | Leave a Comment »