Thursday, December 27, 2007

Build, Rebuild and compile

Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.

Build or Rebuild Solution builds or rebuilds all projects in the your solution, while Build or Rebuild builds or rebuilds the StartUp project. To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. The project name now appears in bold. Since the homework solutions typically have only one project, Build or Rebuild Solution is effectively the same as Build or Rebuild .

Compile just compiles the source file currently being edited. Useful to quickly check for errors when the rest of your source files are in an incomplete state that would prevent a successful build of the entire project. Ctrl-F7 is the shortcut key for Compile.


kick it on DotNetKicks.com

हेमंत

Tuesday, July 3, 2007

Retrieving Distinct string values without using Distinct in T-SQL

I don’t know many developers to have not used Distinct in the queries at one time or the other. If you look up distinct in SQL Server Book it is defined as “Returns a set, removing duplicate tuples from a specified set.” True but not quite, when used for string column it also sorts the column alphabetically by default you like it or not.



Recently I came across a scenario where I needed to get distinct string values sorted by date time without sorting it in alphabetical order. I was dumb struck to find none of the SQL Server methods provided direct support to do so. I finally came up with the below mentioned process to achieve this, though would not say that it’s the best way forward, but till I find a better way, I am sharing the best I know.

DECLARE @Table1 TABLE
(
ID INT IDENTITY,
Value VARCHAR(50)
)

DECLARE @Table2 TABLE
(
ID INT IDENTITY,
Value VARCHAR(50)
)




INSERT INTO @Table1(Value)
Values('A')

INSERT INTO @Table1(Value)
Values('Z')

INSERT INTO @Table1(Value)
Values('B')

INSERT INTO @Table1(Value)
Values('F')

INSERT INTO @Table1(Value)
Values('A')

INSERT INTO @Table1(Value)
Values('F')

INSERT INTO @Table1(Value)
Values('N')

INSERT INTO @Table1(Value)
Values('C')

INSERT INTO @Table1(Value)
Values('N')

INSERT INTO @Table1(Value)
Values('B')

DECLARE @LOOP
INT
DECLARE @COUNT INT
SET @LOOP =1
SELECT @COUNT = Count(*) FROM @TABLE1
WHILE @COUNT>=@Loop
BEGIN
DECLARE @VALUE VARCHAR(50)
SELECT @VALUE = VALUE From @TABLE1 Where
mailto:ID=@Loop

IF NOT EXISTS (SELECT * FROM @TABLE2 Where VALUE = @VALUE)
BEGIN
INSERT INTO @TABLE2(VALUE)
VALUES (@VALUE)
END
SET @Loop = @Loop +1
END

SELECT * FROM @TABLE2




kick it on DotNetKicks.com


Please provide comments on the method defined. Also please enlighten me with any other approach that I have over looked.

Thursday, June 21, 2007

Retrieving Nth Salary in SQL Server 2000 and 2005

Recently I came across a post in ASP.Net Forum where a user had asked for a Query for Nth Salary retrieval from employee table using SQL query. Strangely on further searching the net I found quite a few people had posted similar query on the net with no answered, here is my answer

SQL Server 2000

Declare @Table
Table
(
EID INT Identity,
ESalary INT
)

Insert into @Table(ESalary)
Values (400)

Insert into @Table(ESalary)
Values (4100)

Insert into @Table(ESalary)
Values (1400)

Insert into @Table(ESalary)
Values (2400)

Insert into @Table(ESalary)
Values (4300)


Select * From @Table [T1] Where
(2 = (Select Count(Distinct [ESalary]) From @Table [T2] where [T1]।[ESalary] <= [T2].[ESalary])) Just replace 2 by any digit 3,4,5। and it will work


SQL Server 2005

SQL Server 2005 provides a new function, Row_Number(), for generating row numbers, this function is used in conjunction with over for generating Ranks/ Rowids staring from 1 for the first row in each partition. I will be posting in more detail regading this feature in my next post. meanwhile you should be able to see how simple the job has become with SQL Server 2005

SELECT

*

FROM (

SELECT EID,ESalary,row_number() OVER (ORDER BY ESalary) AS Rank

FROM @Table

) t1

WHERE Rank=2


kick it on DotNetKicks.com


हेमंत गुप्ता


Tuesday, June 19, 2007

Ten CSS tricks you may not know

I Liked this post on CSS on Digg.com. The author has done a good job of explaining CSS Tricks by Example.

Cascading Style Sheets are the foundation on which many of the best websites are built. Using CSS allows developers to describe the common style for the website, in terms of colours, fonts and layouts. In this tutorial, Trenton Moss of Webcredible shares some of his top tips to help you get the most from your CSS.

read more

हेमंत गुप्ता

Monday, June 11, 2007

Enterprise Library


Enterprise Library is what can be called .NET 2.0's version of application blocks used in .NET 1.1. I had a ball using application blocks in 1.1 and hope the same for Enterprise Library. below is a brief description as found on MSDN site and some other links i found. i have yet to use them extensively thus i will reserve my comments.



The Enterprise Library application blocks help address the common problems that developers face from one project to the next. They are designed to encapsulate the Microsoft recommended best practices for .NET applications. In addition, they can be added to .NET applications quickly and easily. For example, the Data Access Application Block provides access to the most frequently used features of ADO.NET 2.0 in simple-to-use classes, thus boosting developer productivity. It also addresses scenarios not directly supported by the underlying class libraries.
Different applications have different requirements, and you will not find that every application block is useful in every application that you build. Before using an application block, you should have a good understanding of your application requirements and of the scenarios that the application block is designed to address.


Enterprise Library 3.1–May 2007 contains the following general purpose application blocks:
Caching Application Block. Developers can use this application block to incorporate a local cache in their applications.
Cryptography Application Block. Developers can use this application block to incorporate hashing and symmetric encryption in their applications.
Data Access Application Block. Developers can use this application block to incorporate standard database functionality in their applications.
Exception Handling Application Block. Developers and policy makers can use this application block to create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications.
Logging Application Block. Developers can use this application block to include standard logging functionality in their applications.
Policy Injection Application Block. Developers can use this application block to implement interception policies that can be used to streamline the implementation of common features, such as logging, caching, exception handling, and validation, across an application.
Security Application Block. Developers can use this application block to incorporate authorization and security caching functionality in their applications.
Validation Application Block. Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications.
Enterprise Library also includes a set of core functions, including configuration, instrumentation, and object builder services। These functions are used by all other application blocks.











Have a good time. also those who read my blog by pure chance, please leave a comment on how you find my blog.


kick it on DotNetKicks.com

हेमंत गुप्ता

Thursday, June 7, 2007

Membership and Roles in ASP.NET 2.0

Membership is a cool feature from MS which frees the developer from the hassels to creating a user (Registartion Process), Validating the user at login, or roles access across the site. just a great new feature, i am relatively new to the feature thus i am just sharring a few very good links that will help you.

ASP.NET membership gives you a built-in way to validate and store user credentials. ASP.NET membership therefore helps you manage user authentication in your Web sites. You can use ASP.NET membership with ASP.NET Forms authentication or with the ASP.NET login controls to create a complete system for authenticating users.

हेमंत गुप्ता

Tuesday, May 1, 2007

Performance and Scalability Issues in .NET

Memory misuse. If you create too many objects, fail to properly release resources, preallocate memory, or explicitly force garbage collection, you can prevent the CLR from efficiently managing memory. This can lead to increased working set size and reduced performance.

Resource cleanup. Implementing finalizers when they are not needed, failing to suppress finalization in the Dispose method, or failing to release unmanaged resources can lead to unnecessary delays in reclaiming resources and can potentially create resource leaks.

Improper use of threads. Creating threads on a per-request basis and not sharing threads using thread pools can cause performance and scalability bottlenecks for server applications. The .NET Framework provides a self-tuning thread pool that should be used by server-side applications.

Abusing shared resources. Creating resources per request can lead to resource pressure, and failing to properly release shared resources can cause delays in reclaiming them. This quickly leads to scalability issues.

Type conversions. Implicit type conversions and mixing value and reference types leads to excessive boxing and unboxing operations. This impacts performance.

Misuse of collections. The .NET Framework class library provides an extensive set of collection types. Each collection type is designed to be used with specific storage and access requirements. Choosing the wrong type of collection for specific situations can impact performance.

Inefficient loops. Even the slightest coding inefficiency is magnified when that code is located inside a loop. Loops that access an object’s properties are a common culprit of performance bottlenecks, particularly if the object is remote or the property getter performs significant work.

kick it on DotNetKicks.com

Design Considerations

The largest contributing factor to application performance is the application architecture and design. Make sure performance is a functional requirement that your design and test performance takes into account throughout the application development life cycle. Application development should be an iterative process. Performance testing and measuring should be performed between iterations and should not be left to deployment time.

The major design considerations to consider when you design managed code solutions:
● Design for efficient resource management.
● Reduce boundary crossings.
● Prefer single large assemblies rather than multiple smaller assemblies.
● Factor code by logical layers.
● Treat threads as a shared resource.
● Design for efficient exception management.

Design for Efficient Resource Management
Avoid allocating objects and the resources they encapsulate before you need them, and make sure you release them as soon as your code is completely finished with them. This advice applies to all resource types including database connections, data readers, files, streams, network connections, and COM objects. Use finally blocks or Microsoft Visual C#® using statements to ensure that resources are closed or released in a timely fashion, even in the event of an exception. Note that the C# using statement is used only for resources that implement IDisposable; whereas finally blocks can be used for any type of cleanup operations.

Reduce Boundary Crossings
Aim to reduce the number of method calls that cross remoting boundaries because this introduces marshaling and potentially thread switching overhead. With managed code, there are several boundaries to consider:

● Cross application domain. This is the most efficient boundary to cross because it is within the context of a single process. Because the cost of the actual call is so low, the overhead is almost completely determined by the number, type, and size of parameters passed on the method call.

● Cross process. Crossing a process boundary significantly impacts performance. You should do so only when absolutely necessary. For example, you might determine that an Enterprise Services server application is required for security and fault tolerance reasons. Be aware of the relative performance tradeoff.

Cross machine. Crossing a machine boundary is the most expensive boundary to cross, due to network latency and marshaling overhead. While marshaling overhead impacts all boundary crossings, its impact can be greater when crossing machine boundaries. For example, the introduction of an HTTP proxy might force you to use SOAP envelopes, which introduces additional overhead. Before introducing a remote server into your design, you need to consider the relative tradeoffs including performance, security, and administration.

Unmanaged code. You also need to consider calls to unmanaged code, which introduces marshaling and potentially thread switching overhead. The Platform Invoke (P/Invoke) and COM interop layers of the CLR are very efficient, but performance can vary considerably depending on the type and size of data that needs to be marshaled between the managed and unmanaged code.

Prefer Single Large Assemblies Rather Than Multiple Smaller Assemblies
To help reduce your application’s working set, you should prefer single larger assemblies rather than multiple smaller assemblies. If you have several assemblies that are always loaded together, you should combine them and create a single assembly. The overhead associated with having multiple smaller assemblies can be attributed to the following:

● The cost of loading metadata for smaller assemblies.
● Touching various memory pages in pre-compiled images in the CLR in order
to load the assembly (if it is precompiled with Ngen.exe).
● JIT compile time.
● Security checks.

Because you pay for only the memory pages your program accesses, larger assemblies provide the Native Image Generator utility (Ngen.exe) with a greater chance to optimize the native image it produces. Better layout of the image means that necessary data can be laid out more densely, which in turn means fewer overall pages are needed to do the job compared to the same code laid out in multiple assemblies. Sometimes you cannot avoid splitting assemblies; for example, for versioning and deployment reasons. If you need to ship types separately, you may need separate assemblies.

Factor Code by Logical Layers
Consider your internal class design and how you factor code into separate methods. When code is well factored, it becomes easier to tune to improve performance, maintain, and add new functionality. However, there needs to be a balance. While clearly factored code can improve maintainability, you should be wary of over abstraction and creating too many layers. Simple designs can be effective and efficient.

Treat Threads as a Shared Resource
Do not create threads on a per-request basis because this can severely impact scalability. Creating new threads is also a fairly expensive operation that should be minimized. Treat threads as a shared resource and use the optimized .NET thread pool.

Design for Efficient Exception Management
The performance cost of throwing an exception is significant. Although structured exception handling is the recommended way of handling error conditions, make sure you use exceptions only in exceptional circumstances when error conditions occur. Do not use exceptions for regular control flow.

Thursday, April 26, 2007

Introduction

Hi all,
I am Hemant Gupta from Amritsar, India. I am working as Delivery Head in Graycell Technologies Chandigarh. I am a great fan of Microsoft technologies, and currently working on .NET Technology 1.1 & 2.0 with SQL server 2000/2005. I do not pretend to know it all, but i consider myself to be an efficient coder. This is my first attempt at a blog, i will be adding posts related to .NET in coming weeks for all to see, hope they help someone out there.

I have had a great carrier graph but a tough one with a steep learing curve, i stared of as an ASP.Net developer in a small company worked there for 14 months and then got an offer to work as Team Lead in Graycell Technologies Exports, and have been with the company till date. Moving through the ranks I have moved up to Delivery Head.