Thursday, March 31, 2011

SQL SERVER – Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value

How to get 1st, 2nd, 3rd, 4th, nth topmost salary from an Employee table
The following solution is for getting 6th highest salary from Employee table ,

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

You can change and use it for getting nth highest salary from Employee table as follows

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)

Same example converted in SQL Server 2005 to work with Database AdventureWorks.
USE AdventureWorks;
GO
SELECT TOP 1 Rate
FROM (
SELECT DISTINCT TOP 4 Rate
FROM HumanResources.EmployeePayHistory
ORDER BY Rate DESC) A
ORDER BY Rate
GO

Sunday, March 27, 2011

.Net FAQ


  • Difference between a.Equals(b) and a == b If both a and b are value type then then you will get same result in a.Equals(b) and a == b. but in case of reference type both behaves differently : eg. string a = new string(new char[] {'d', 'a', 'n', 'c', 'e'}); string b = new string(new char[] {'d', 'a', 'n', 'c', 'e'}); object c = a; object d = b; Console.WriteLine (a==b); Console.WriteLine (a.Equals(b)); Console.WriteLine (c==d); Console.WriteLine (c.Equals(d)); } } Output will be; True True False True FAQ

Master page events Events



  • Master Page Child Control Initialization

  • Content Page Child Control Initialization

  • Master Page Initialization

  • Content Page Initialization

  • Content Page Load

  • Master Page Load

  • Master Page Child Controls Load

  • Content Page Child Controls Load

How IIS Process ASP.NET Request http://www.dotnetfunda.com/articles/article821-beginners-guide-how-iis-process-aspnet-request-.aspx

http://computerauthor.blogspot.com/2011/04/sql-server-interview-question-what-is.html

Wednesday, March 16, 2011

What is CLR,CLS,CTS,MSIL,JIT??

What is a .Net Assembly?

The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.

There are two kind of assemblies in .NET:

private
shared
Private assemblies are simple and copied with each calling assemblies in the calling assemblies folder.

Shared assemblies (also called strong named assemblies) are copied to a single location (usually the Global assembly cache). For all calling assemblies within the same application, the same copy of the shared assembly is used from its original location. Hence, shared assemblies are not copied in the private folders of each calling assembly. Each shared assembly has a four part name including its face name, version, public key token and culture information. The public key token and version information makes it almost impossible for two different assemblies with the same name or for two similar assemblies with different version to mix with each other.

An assembly can be a single file or it may consist of the multiple files. In case of multi-file, there is one master module containing the manifest while other assemblies exist as non-manifest modules. A module in .NET is a sub part of a multi-file .NET assembly. Assembly is one of the most interesting and extremely useful areas of .NET architecture along with reflections and attributes, but unfortunately very few people take interest in learning such theoretical looking topics.

What are the basic components of .NET platform?
The basic components of .NET platform (framework) are:

.Net Applications

(Win Forms,Web Applications,Web Services)

Data(ADO.Net) and XML Library
FrameWork Class Library(FCL)

(IO,Streams,Sockets,Security,Reflection,UI)

Common Language Runtime(CLR)

(Debugger,Type Checker,JITer,GC)

Operating System

(Windows,Linux,UNIX,Macintosh,etc.,)



Common Language Runtime (CLR):
The most important part of the .NET Framework is the .Net Common Language Runtime (CLR) also called .Net Runtime in short. It is a framework layer that resides above the Operating System and handles/manages the execution of the .NET applications. Our .Net programs don't directly communicate with the Operating System but through CLR.

MSIL (Microsoft Intermediate Language) Code:
When we compile our .Net Program using any .Net compliant language like (C#, VB.NET, C++.NET) it does not get converted into the executable binary code but to an intermediate code, called MSIL or IL in short, understandable by CLR. MSIL is an OS and H/w independent code. When the program needs to be executed, this MSIL or intermediate code is converted to binary executable code, called native code. The presence of IL makes it possible the Cross Language Relationship as all the .Net compliant languages produce the similar standard IL code.

Just In Time Compilers (JITers):
When our IL compiled code needs to be executed, CLR invokes JIT compilers which compile the IL code to native executable code (.exe or .dll) for the specific machine and OS. JITers in many ways are different from traditional compilers as they, as their name suggests, compile the IL to native code only when desired e.g., when a function is called, IL of function's body is converted to native code; just in time of need. So, the part of code that is not used by particular run is not converted to native code. If some IL code is converted to native code then the next time when its needed to be used, the CLR uses the same copy without re-compiling. So, if a program runs for sometime, then it won't have any just in time performance penalty. As JITers are aware of processor and OS exactly at runtime, they can optimize the code extremely efficiently resulting in very robust applications. Also, since JITer knows the exact current state of executable code, they can also optimize the code by in-lining small function calls (like replacing body of small function when its called in a loop, saving the function call time).

Framework Class Library (FCL):

.NET Framework provides huge set of Framework (or Base) Class Library (FCL) for common, usual tasks. FCL contains thousands of classes to provide the access to Windows API and common functions like String Manipulation, Common Data Structures, IO, Streams, Threads, Security, Network Programming, Windows Programming, Web Programming, Data Access, etc. It is simply the largest standard library ever shipped with any development environment or programming language. The best part of this library is they follow extremely efficient OO design (design patterns) making their access and use very simple and predictable. You can use the classes in FCL in your program just as you use any other class and can even apply inheritance and polymorphism on these.

Common Language Specification (CLS):
Earlier we used the term '.NET Compliant Language' and stated that all the .NET compliant languages can make use of CLR and FCL. But what makes a language '.NET compliant language'? The answer is Common Language Specification (CLS). Microsoft has released a small set of specification that each language should meet to qualify as a .NET Compliant Language. As IL is a very rich language, it is not necessary for a language to implement all the IL functionality, rather it meets the small subset of it, CLS, to qualify as a .NET compliant language, which is the reason why so many languages (procedural and OO) are now running under .Net umbrella. CLS basically addresses to language design issues and lays certain standards like there should be no global function declaration, no pointers, no multiple inheritance and things like that. The important point to note here is that if you keep your code within CLS boundary, your code is guaranteed to be usable in any other .Net language.

Common Type System (CTS):
.NET also defines a Common Type System (CTS). Like CLS, CTS is also a set of standards. CTS defines the basic data types that IL understands. Each .NET compliant language should map its data types to these standard data types. This makes it possible for the 2 languages to communicate with each other by passing/receiving parameters to/from each other. For example, CTS defines a type Int32, an integral data type of 32 bits (4 bytes) which is mapped by C# through int and VB.Net through its Integer data type.

Garbage Collector (GC):
CLR also contains Garbage Collector (GC) which runs in a low-priority thread and checks for un-referenced dynamically allocated memory space. If it finds some data that is no more referenced by any variable/reference, it re-claims it and returns the occupied memory back to the Operating System; so that it can be used by other programs as necessary. The presence of standard Garbage Collector frees the programmer from keeping track of dangling data.

Monday, March 14, 2011

Sharepoint 2010 Virtual lab

Tuesday, March 8, 2011

Publish a .NET 3.5 Website to Windows Server 2008 IIS 7

Publish a .NET 3.5 Website to Windows Server 2008 IIS 7
Install the Web Server Role

•In Role Services, select ASP.NET and continue.
Install the .NET 3.5 Framework
•On your webserver, install the .NET 3.5 framework.

Publish Your Application
•In Visual Studio, publish your web project to a local folder, like on the desktop.
•Copy that folder to a local folder on the webserver, maybe somewhere like c:\apps.
•From the IIS Manager, right click your Default Web Site and "Add Application". I ran the "Test Settings" button and there was an authorization warning but I continued on.

Enable ASP.NET Impersonation on your Website
•If you're using Forms authentication, I think it's necessary to enable this setting, otherwise your permissions aren't in effect and anyone can browse anywhere.
•IIS -> Your website -> Authentication -> Enable ASP.NET Impersonation.

Test your Application
•Open a browser, and try http://localhost, verify that the IIS 7 page comes up and you know IIS 7 is installed correctly.
•Then test your application by browsing to http://localhost/your_application.

Troubleshooting
•If you receive .NET 3.5.0.0 reference errors or csc.exe not found, make sure you've installed the .NET 3.5 framework.
•If your web page does not display correctly, or images are missing, check all of your url links. I had to fix lots of url links, images, scripts, css files, sitemap files. I've learned it's best to replace any css or html url links with asp.net objects. For example, instead of using the IMG html tag (which VS creates if you drag an image onto the designer), use the tag instead. And for all of your url links, use an absolute path like "~/Images/".
•If you receive an error connecting to a local database, "Invalid login for NT AUTHORITY/NETWORK SERVICE"... open SQL Management Studio, add a new login, find the NETWORK SERVICE credential and grant that login db_owner permissions for your database.


Exploring the Global.asax file in ASP.NET

Exploring the Global.asax file in ASP.NET
Have you ever felt the need of writing logic at the application level; precisely a location or a file where you could handle events or errors at the application level? Well if yes, then enter the Global.asax. Using this file, you can define event handlers with application-wide or session-wide scope. In this article, we will explore the application and session level events exposed in the Global.asax file and how we can utilize these events in our applications.

The Global.asax, also known as the ASP.NET application file, is located in the root directory of an ASP.NET application. This file contains code that is executed in response to application-level and session-level events raised by ASP.NET or by HTTP modules. You can also define ‘objects’ with application-wide or session-wide scope in the Global.asax file. These events and objects declared in the Global.asax are applied to all resources in that web application.

Note 1: The Global.asax is an optional file. Use it only when there is a need for it.
Note 2: If a user requests the Global.asax file, the request is rejected. External users cannot view the file.

The Global.asax file is parsed and dynamically compiled by ASP.NET. You can deploy this file as an assembly in the \bin directory of an ASP.NET application.
How to create Global.asax

Adding a Global.asax to your web project is quiet simple.
Open Visual Studio 2005 or 2008 > Create a new website > Go to the Solution Explorer > Add New Item > Global Application Class > Add.
Examining the methods related to the events in Global.asax
There are 2 ‘set’ of methods that fire corresponding to the events. The first set which gets invoked on each request and the second set which does not get invoked on each request. Let us explore these methods.

Methods corresponding to events that fire on each request

Application_BeginRequest() – fired when a request for the web application comes in.
Application_AuthenticateRequest –fired just before the user credentials are authenticated. You can specify your own authentication logic over here.
Application_AuthorizeRequest() – fired on successful authentication of user’s credentials. You can use this method to give authorization rights to user.
Application_ResolveRequestCache() – fired on successful completion of an authorization request.
Application_AcquireRequestState() – fired just before the session state is retrieved for the current request.
Application_PreRequestHandlerExecute() - fired before the page framework begins before executing an event handler to handle the request.
Application_PostRequestHandlerExecute() – fired after HTTP handler has executed the request.
Application_ReleaseRequestState() – fired before current state data kept in the session collection is serialized.
Application_UpdateRequestCache() – fired before information is added to output cache of the page.
Application_EndRequest() – fired at the end of each request
Methods corresponding to events that do not fire on each request
Application_Start() – fired when the first resource is requested from the web server and the web application starts.
Session_Start() – fired when session starts on each new user requesting a page.
Application_Error() – fired when an error occurs.
Session_End() – fired when the session of a user ends.
Application_End() – fired when the web application ends.
Application_Disposed() - fired when the web application is destroyed.

Tuesday, March 1, 2011

Installing SharePoint Server-2010

Installing SharePoint Server-2010

1)How to install SPS2010 in Single Box Development Server?



2)Create a Sharepoint 2010 VM in 32 bits host machine
Download doc for details



1)How to install SPS2010 in Single Box Development Server?

1. After you have finished installing OS, start to add Active Directory Domain Service roles.
Complete the installation procedure and configure the roles.
2. Then, start to add Application Server and Web Server roles.
This installation is straight forward, and you will be easily get your Application Server and Web Server roles configured in the machine.
3. Install SQL Server 2008 SP1 + CU KB970315
Download SQL Server 2008 SP1 here: http://www.microsoft.com/downloads/details.aspx?familyid=66AB3DBB-BF3E-4F46-9559-CCC6A4F9DC19&displaylang=en

Download CU KB970315 here: http://support.microsoft.com/kb/970315

And here is the tricky part, installing SPS2010

4. Extract SPS2010 installer to a folder

/extract:e:\sps2010

That command will extract to folder e:\sps2010. Replace with your own distribution.

5. You will see that there is several sub-folder under Files folder in the extracted location. Each sub-folder represents different setup option. For example, SetupFarm contains configuration files for farm installation option etc.

6. Start the installation sequence by executing following command in the extracted location.

Setup.exe /config Files\SetupFarm\config.xml


Refer:

http://andreasglaser.net/post/2009/11/17/Installing-SharePoint-Server-2010-on-Windows-Server-2008-R2-and-SQL-Server-2008-R2-Part-1-Overview.aspx

http://www.ericharlan.com/Moss_SharePoint_2007_Blog/how-to-install-sharepoint-2010-guide-a166.html

Popular Posts

Recent Posts

Unordered List

Text Widget

Blog Archive