Wednesday, September 30, 2009

Check/ Uncheck all child nodes of a node in TreeView

when we need to Check/ Uncheck all chield nodes of anynode in TreeView we need to create a recursive function which will do check all to all child nodes of the current node and voice-versa.

Private Sub tvrights_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvrights.AfterCheck
RemoveHandler tvrights.AfterCheck, AddressOf tvrights_AfterCheck
CheckChildNode(e.Node)
CheckParentNode(e.Node)
AddHandler tvrights.AfterCheck, AddressOf tvrights_AfterCheck
End Sub



Private Sub CheckChildNode(ByVal currNode As TreeNode)
'set the children check status to the same as the current node
Dim checkStatus As Boolean = currNode.Checked
For Each node As TreeNode In currNode.Nodes
node.Checked = checkStatus
CheckChildNode(node)
Next
End Sub

Private Sub CheckParentNode(ByVal currNode As TreeNode)
Dim parentNode As TreeNode = currNode.Parent
If parentNode Is Nothing Then Exit Sub
parentNode.Checked = True
For Each node As TreeNode In parentNode.Nodes
If Not node.Checked Then
parentNode.Checked = False
Exit For
End If
Next
CheckParentNode(parentNode)
End Sub
Read More

Visit all Nodes of TreeView

when we need to traverse all nodes of a treeview then we will have to create a recursive function.
In below example we are showing how to visit all nodes of treeview.
eg:-

Private Sub TraverseTreeView(ByVal tview As TreeView)
Dim temp As New TreeNode
For k As Integer = 0 To tview.Nodes.Count - 1
temp = tview.Nodes(k)
messagebox.show(temp) 'this will show node text
For i As Integer = 0 To temp.Nodes.Count - 1
visitChildNodes(temp.Nodes(i))
Next
Next
End Sub

Private Sub visitChildNodes(ByVal node As TreeNode)

messagebox.show(node) 'this will show node text
For j As Integer = 0 To node.Nodes.Count - 1
visitChildNodes(node.Nodes(j))
Next
End Sub
Read More

Monday, September 28, 2009

Custom Page Size Crystal Report by Code

Dim oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
oRpt.Load(Server.MapPath("CrystalReport.rpt"))
oRpt.PrintOptions.PaperOrientation = [Shared].PaperOrientation.Portrait
oRpt.PrintOptions.PaperSize = [Shared].PaperSize.PaperEnvelope10

CrystalReportViewer1.ReportSource = oRpt
Read More

Tuesday, September 22, 2009

Repair a database

Repair a database

To determine whether a database needs to be repaired run:

dbcc checkdb('DB-NAME') with no_infomsgs
replacing 'DB-NAME' with the name of the database.

If this completes without displaying any errors then the database does not need to be repaired.

If the errors that come back contain lines saying:

... Run DBCC UPDATEUSAGE
Then the database does not need to be repaired, simply run:

dbcc updateusage('DB-NAME') with no_infomsgs
If a database does need to be repaired then:

if you can identify why the database needs to be repaired. Look in the windows system and application event logs to see if any problems have been logged which might account for the problem. For example is the problem caused by a failing disk? Often you will not be able to identify the cause, but if you can then remember to address it.
it is suggested that instead of repairing the database it be restored from the last reliable backup.
To repair a database the database must first be placed into single user mode:

alter database DB-NAME set SINGLE_USER

once the database is in single user mode it can be repaired. There are a number of repair options but the two typically used are "REPAIR_REBUILD" and "REPAIR_ALLOW_DATA_LOSS". I suggest in the first instance using:

dbcc checkdb('DB-NAME',REPAIR_REBUILD)
this will make any repairs that SQL Server can perform without the loss of data.

If (and only if) SQL Server cannot repair the database without the loss of data then use:

dbcc checkdb('DB-NAME',REPAIR_ALLOW_DATA_LOSS)
once the database has been repaired it should be switched out of single user mode and back into multi-user mode:

set database DB-NAME set MULTI_USER
These notes have been tested against SQL Server 2005 running under Windows 2008 Standard Server.
Read More

Monday, September 14, 2009

Static Class

Static classes are used when a class provides functionality that is not specific to any unique instance. Here are the features of static classes in C# 2.0.

Static classes can not be instantiated.
Static classes are sealed so they can not be inherited.
Only static members are allowed.
Static classes can only have static constructor to initialize static members.
Advantages

Compiler makes sure that no instance of static class is created. In previous version of C#, the constructor has to be marked private to avoid this from happening.

Also compiler makes sure that no instance members are declared within a static class.

Sample:

Public static class MyStaticClass
{
Private static int _staticVariable;
Public static int staticVariable;
{
Get
{
Return _staticVariable;
}
Set
{
_staticVariable = value;
}
}
Public static void Function()
{
}
}

--------------***********************----------------------------------------
A static class is defined as a class that contains only static members (of course besides the instance members inherited from System.Object and possibly a private constructor). Some languages provide built-in support for static classes. In C# 2.0, when a class is declared to be static, it is sealed, abstract, and no instance members can be overridden or declared.
public static class File {
...
}
If your language does not have built-in support for static classes, you can declare such classes manually as in the following C++ example:
public class File abstract sealed {
...
}
Static classes are a compromise between pure object-oriented design and simplicity. They are commonly used to provide shortcuts to other operations (such as System.IO.File), or functionality for which a full object-oriented wrapper is unwarranted (such as System.Environment).
DO use static classes sparingly.
Static classes should be used only as supporting classes for the object-oriented core of the framework.
DO NOT treat static classes as a miscellaneous bucket.
There should be a clear charter for the class.
DO NOT declare or override instance members in static classes.
DO declare static classes as sealed, abstract, and add a private instance constructor, if your programming language does not have built-in support for static classes.

Example of Static Class in C#.net

using System;

static class MathFunction {
// Return the reciprocal of a value.
static public double reciprocal(double num) {
return 1/num;
}

// Return the fractional part of a value.
static public double fracPart(double num) {
return num - (int) num;
}

// Return true if num is even.
static public bool isEven(double num) {
return (num % 2) == 0 ? true : false;
}

// Return true of num is odd.
static public bool isOdd(double num) {
return !isEven(num);
}

}

class MainClass {
public static void Main() {
Console.WriteLine("Reciprocal of 5 is " +
MathFunction.reciprocal(5.0));

Console.WriteLine("Fractional part of 4.234 is " +
MathFunction.fracPart(4.234));

if(MathFunction.isEven(10))
Console.WriteLine("10 is even.");

if(MathFunction.isOdd(5))
Console.WriteLine("5 is odd.");

// The following attempt to create an instance of
// MathFunction will cause an error.
// MathFunction ob = new MathFunction(); // Wrong!
}
}
Read More

Difference between Function Overriding and Function Overloading

Difference between Function Overriding and Function Overloading

Overriding is the example of run-time polymorphism and
Overloading is the example of compile-time polymorphism.

The Compile-Time polymorphism have early binding and
Runtime polymorphism have late binding.

The Compile-Time polymorphism is Static and
Runtime polymorphism is Dynamic.

Overriding
¦The return type must exactly match that of the overridden method (Note:- in some languages we can change Return type in overriding).

¦The access level must not be more restrictive than that of the overridden method.

¦The access level can be less restrictive than that of the overridden method.

¦The overriding method must not throw new or broader checked exceptions than those declared by the overridden method.

¦The overriding method can throw narrower or fewer exceptions. Just because an overridden method “takes risks” doesn’t mean that the overriding subclass’ exception takes the same risks. Bottom line: An overriding method doesn’t have to declare any exceptions that it will never throw, regardless of what the overridden method declares.

¦You cannot override a method marked final.

¦Overriding is only possible through inheritance.

¦If a method can’t be inherited, you cannot override it.

Overloaded method
¦Overloaded methods must change the argument list (you can do change in argument list by 1. changing datatype of parameters, 2. changing sequence of parameters, 3. changing count of parameters).

¦Overloaded methods can change the return type (mins its doesn't make any difference that either you change return type or not. its not matter for overloading)

¦Overloaded methods can change the access modifier.

¦Overloaded methods can declare new or broader checked exceptions.

¦A method can be overloaded in the same class or in a subclass.

NOTE:- all most all object oriented languages supports function overloading and function overriding and some of languages also supports operator overloading like : c#.net , c++ etc and some languages not support operator overloading like: vb.net but no language support operator overriding.
Read More

Special folders in ASP.Net

With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.Net by introducing a suite of new features and functionalities.

ASP.Net defines several special folders. When a new Web site is created the App_Data folder is created by default; it can contain a SQL Server 2005 Express Edition database, another database, or an XML data file that will be used in the Web site.

These folders are also data directories.

~:App_Browsers folder - Contains browser definitions (.browser files) files that ASP.Net uses to identify individual browsers and determine their capabilities. Browser definition files are used to determine the client browser capabilities. These files are often used to help support mobile application.

~:App_Data folder - App_Data folder is used to store file that can be used as database files (.mdf, .mdb and xml files). The user account that is used to run the application (for example, the local ASPNET account) has permissions to read, write, and create files in this folder. Various ASP.NET application features, such as the providers for membership and roles, as well as the Web Site Administration Tool, are configured to work with the App_Data folder specifically.

~:Bin folder - Contains compiled assemblies (.dll files), for code that you want to reference in your application, as in earlier versions of Visual Studio. Any classes represented by code in the Bin folder are automatically referenced in your Web site.

~:App_LocalResources folder - Contains .resx files that are bound to a specific page. You can define multiple .resx files for each page, each .resx file representing a different language or language/culture combination.

~:App_GlobalResource folder - Like the App_LocalResources folders, but contains .resx files that are not bound to a specific page. Resource values in .resx files in the App_GlobalResource folders can be accessed programmatically from application code.

~:App_Code folder - Contains source code files. The code is compiled as part of your application and is referenced automatically. The App_Code folder works much like the Bin folder, except that you can put source code in it instead of compiled code. While you are working in Visual Web Developer, the source code in the App_Code folder is compiled dynamically so that IntelliSense can reference any classes defined in the files.

~:App_Themes folder - Contain sub-folders that each defines a specific theme or look and feel for you Web site. Sub-folders consist of a collection of files (such as .skin, .css and image files) that define the appearance of ASP.Net Web pages and controls.

~:App_WebReferences folder - Contains files used to create a reference to a Web service (in the same project or external to the project), including .disco, .xsd, .discomap and .wsdl files.

Note: Special folders can be added to a Web site from the Visual Studio menu system. Typically this involves right-clicking the Web Application project and selecting Add ASP.NET folder.
Read More

Special folders in ASP.Net

With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.Net by introducing a suite of new features and functionalities.

ASP.Net defines several special folders. When a new Web site is created the App_Data folder is created by default; it can contain a SQL Server 2005 Express Edition database, another database, or an XML data file that will be used in the Web site.

These folders are also data directories.

~:App_Browsers folder - Contains browser definitions (.browser files) files that ASP.Net uses to identify individual browsers and determine their capabilities. Browser definition files are used to determine the client browser capabilities. These files are often used to help support mobile application.

~:App_Data folder - App_Data folder is used to store file that can be used as database files (.mdf, .mdb and xml files). The user account that is used to run the application (for example, the local ASPNET account) has permissions to read, write, and create files in this folder. Various ASP.NET application features, such as the providers for membership and roles, as well as the Web Site Administration Tool, are configured to work with the App_Data folder specifically.

~:Bin folder - Contains compiled assemblies (.dll files), for code that you want to reference in your application, as in earlier versions of Visual Studio. Any classes represented by code in the Bin folder are automatically referenced in your Web site.

~:App_LocalResources folder - Contains .resx files that are bound to a specific page. You can define multiple .resx files for each page, each .resx file representing a different language or language/culture combination.

~:App_GlobalResource folder - Like the App_LocalResources folders, but contains .resx files that are not bound to a specific page. Resource values in .resx files in the App_GlobalResource folders can be accessed programmatically from application code.

~:App_Code folder - Contains source code files. The code is compiled as part of your application and is referenced automatically. The App_Code folder works much like the Bin folder, except that you can put source code in it instead of compiled code. While you are working in Visual Web Developer, the source code in the App_Code folder is compiled dynamically so that IntelliSense can reference any classes defined in the files.

~:App_Themes folder - Contain sub-folders that each defines a specific theme or look and feel for you Web site. Sub-folders consist of a collection of files (such as .skin, .css and image files) that define the appearance of ASP.Net Web pages and controls.

~:App_WebReferences folder - Contains files used to create a reference to a Web service (in the same project or external to the project), including .disco, .xsd, .discomap and .wsdl files.

Note: Special folders can be added to a Web site from the Visual Studio menu system. Typically this involves right-clicking the Web Application project and selecting Add ASP.NET folder.
Read More

What is Code Replacement in ASP.Net

.NET Framework assemblies are typically compiled and deployed into a Windows DLL-based PE format. When the common language runtime's loader resolves a class implemented within this type of assembly, it calls the Windows LoadLibrary routine on the file (which locks its access on disk), and then maps the appropriate code data into memory for run-time execution. Once loaded, the DLL file will remain locked on disk until the application domain referencing it is either torn down or manually recycled.

Although ASP.NET cannot prevent the common language runtime from locking a loaded assembly DLL on disk, it can support you by ensuring that the physical DLLs in a Web application's private assembly cache are never actually loaded by the runtime. Instead, shadow copies of the assembly DLLs are made immediately prior to their use. These shadow assemblies--not the original files--are then locked and loaded by the runtime.

Because the original assembly files always remain unlocked, you are free to delete, replace, or rename them without cycling the Web server or having to use a registration utility. FTP and similar methods work just fine. ASP.NET maintains an active list of all assemblies loaded within a particular application's application domain and uses file-change monitoring code to watch for any updates to the original files.
Read More

Thursday, September 10, 2009

By default the member of the interface are public and abstract. true or false?

True
Read More

By default the member of the interface are public and abstract. true or false?

True
Read More

By default the member of the interface are public and abstract. true or false?

True
Read More

In how many ways you can compare two strings in C# using overloaded methods and operators?

There are three ways:
1. Overloaded Compare() method
2. Overloaded Equal() method
3. Overloaded == operator.
Read More

In how many ways you can create new copies of an existing string in C#?

There are two ways to create new copies of an existing string in C#:
1. Using overloaded = operator like - string s2 = s1;
2. Using the static Copy method like - string s2 = string.Copy(s1);
Read More

What is BOXING and UNBOXING in C#?

BOXING in C# is the conversion of a VALUE type on stack to a OBJECT type on the heap. Vice-versa the conversion from an OBJECT type back to a VALUE type is known as UNBOXING and it requires type casting.
Read More

What are the characteristics of C#?

C# is designed for both computing and communication is characterized by several key features. It is -
1. Simple
2. Consitent
3. Modern
4. Object-oriented
5. Type-safe
6. Versionable
7. Compatible
8. Interoprable and
9. Flexible
Read More

What is C# (C-Sharp)?

C# is a new language created by Microsoft and submitted to the ECMA for standardization. According Microsoft "C# is a modern, object-oriented language that enables programmers to quickly build a wide range of applications for the new Microsoft .Net platform, which provides tools and services that fully exploit both computing and communications."
Read More

What is ASP.Net?

ASP.Net is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server.
1. ASP.Net is a Microsoft Technology
2. ASP stands for Active Server Pages
3.ASP.Net is a program that runs inside IIS
4.IIS (Internet Information Services) is Microsofts Internet server
Read More

Name some of the languages ASP.Net does support?

Some of the languages that are supported by ASP.Net:
1. Visual Basic.Net
2. Visual C#
3. Visual C++
Read More

Can the action attribute of a server side < form > tag be set to a value and if not how can you possibly pass data to another page?

No, You have to use Server.Transfer to pass the data to another page.
Read More

What is a runtime host in ASP.Net?

.Net framework supports different type of applications like Web, windows, console etc,. Each type of application needs a runtime host to start it. This runtime host loads the runtime into a process, creates the application with in the process and loads the application code into the process. Runtime hosts included in .Net framework are
ASP.Net: It loads the runtime that can handle a web request into the process. ASP.NET also creates an application domain for each Web application that will run on a Web server.

Microsoft Internet Explorer: It creates an application domain to run managed controls.
Shell executables: When ever a runtime executable is launched from the shell, this executable invokes the corresponding runtime host.
Read More

What is the .Net framework?

.Net framework is the technology on which .Net applications are developed and deployed. The framework consist of three main components -
1. CLR (Comman Langauge Runtime)
2. Unified Classes (Framework Base Classes)
3. User and Program Interface (ASP.Net, Winforms)
Read More

What are assemblies?

An Assembly is single deployable unit that contains all the information about the implementation of the classes, structures, interfaces and are similar to the DLL files. Both have the reusable pieces of code in the form of classes and functions. DLL needs to be registered but assemblies have its own METADATA.

An assembly stores all the information about itself. This is called METADATA and includes the name and version number of the assembly, security information, information about the dependencies and list of files that constitute the assembly.

Namespaces are also stored in the assemblies. In the .Net framework, applications are deployed in the form of assemblies.
Read More

What is the global assembly cache (GAC)?

GAC is a machine-wide cache of assemblies that allows .Net applications to share libraries. GAC solves the problems associated with dll (DLL Hell).
Read More

Which service in the CLR allocates the memory on the managed heap for an object in ASP.Net?

Code manager.
Read More

How does ASP.Net page works?

1. When a browser requests an HTML file, the server returns the file
2. When a browser requests an ASP.Net file, IIS passes the request to the ASP.Net engine on the server
3. The ASP.Net engine reads the file, line by line, and executes the scripts in the file
4. Finally, the ASP.Net file is returned to the browser as plain HTML.
Read More

How do you debug an ASP.Net Web application?

Attach the aspnet_wp.exe process to the DbgClr debugger.
Read More

What is the default ConnectionTimeOut to wait for a connection to open in ASP.Net?

The default value is 15 seconds.
Read More

How To Find Number of Days between two Dates in C# Asp.Net?

To calculate the number of days between two dates in Asp.Net using C#, use the below piece of code.
TimeSpan timespan = Convert.ToDateTime("2009-12-31").Subtract(Convert.ToDateTime("2009-01-01"));
Response.Write(timespan.Days+1);

Here we use Subtract method to find the difference between two dates. Usually the Subtract method return a value that is one less than the correct value. So to the Timespan object Days property we can add 1 to get the exact number of days.
Read More

Wednesday, September 9, 2009

Session State Management Using SQL Server in ASP.NET

Web applications are by nature stateless. Statelessness is both an advantage and a disadvantage. When resources are not being consumed by maintaining connections and state, scalability is tremendously improved. But the lack of state reduces functionality severely. ECommerce applications require state to be maintained as the user navigates from page to page. ASP.NET’s Session object makes it easy for developers to maintain state in a Web application. State can be maintained in-process, in a session state server, or in SQL Server.

In-process state management is the ASP.NET default, and it offers the fastest response time, but does not work in a Web farm. Consequently, it is not practical in high capacity Web applications requiring the load to be spread over multiple servers. A dedicated session state server is shared by all servers in a Web farm, so it provides scalability of the Session objects across all Web servers. It cannot store state persistently. If a dedicated session state server goes down for any reason, all session state data is lost. SQL Server is another alternative for storing session state for all of the servers in a Web farm. Since SQL Server is a database, there is a popular misconception that ASP.NET session state maintained in SQL Server is stored persistently. By default, it is not. If the SQL Server is stopped, the session state data is lost. By making a few simple changes, state can be stored persistently. It is important to understand that persistent is not the same thing as permanent. ASP.NET places a time limit (timeout in web.config) on how long a session’s state is maintained. If the SQL Server is configured to store state persistently and it is down for longer than the ASP.NET session timeout interval, the session state data is lost.

Configuring ASP.NET Session State Management
Use the sessionState section of the web.config file to configure an ASP.NET Web application to use a SQL Server for session state management. The session state timeout interval is specified by using the timeout parameter.

By default ASP .NET uses cookies to identify which requests
belong to a particular session.
If cookies are not available, a session can be tracked by
adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
–>
_ mode="SQLServer"
_ stateConnectionString="tcpip=127.0.0.1:42424″
_ sqlConnectionString="data source=127.0.0.1; integrated security=true"
_ cookieless="false"
_ timeout="20″
/>

Configure the SQL Server to store Session objects by running a script to create the ASPState database. The .NET Framework provides a state database configuration script in %SYSTEMROOT%\Microsoft.NET\Framework\v1.0.3705\InstallSqlState.sql. If you open the file, you will see a statement to create a database called ASPState. This probably adds to the confusion about state being persistent. The ASPState database contains stored procedures that create tables in tempdb. The tables in tempdb are where session state is actually stored. Thus, when the SQL Server is shutdown, all session state is lost. This raises an important question: If the SQL Server is never shutdown, will tempdb eventually become 100 percent full and run out of space? Recall that ASP.NET connections automatically time out and their resources are freed up after the timeout duration is exceeded. The InstallSqlState.sql script creates a job called ASPState_Job_DeleteExpiredSessions to delete expired sessions from tempdb. Recall that ASP.NET does not keep session resources alive indefinitely. To support this feature when a SQL Server is used to maintain state, the SQL Server Agent must be running so that the expired session deletion job runs as needed. By default, the job is scheduled to run every minute. It deletes session state rows with an Expires value less than the current time. The account under which the SQL Server Agent runs must have the privilege to execute the DeleteExpiredSessions stored procedure.

ASPState database scripts come in pairs. InstallSqlState.sql creates the database and supporting objects. UninstallSqlState.sql drops the database and all supporting objects (e.g., the job to delete expired sessions). You cannot drop a database if it is in use, so if the UninstallSqlState.sql script fails with this error message:

Server: Msg 3702, Level 16, State 4, Line 4
Cannot drop the database ‘ASPState’ because it is currently in use.

Microsoft Knowledge Base article 311209 says to stop the Web server service to overcome this error. An “uninstallation” failure can still occur even if the Web server service is stopped. Additionally, you might not want to stop the Web server service because that will cause all Web applications on the server to stop. Instead, use the SQL Server Enterprise Manager. Find the processes accessing the ASPState database and delete them. If users are still accessing the application and causing new processes to be created faster than you can delete them, go to the IIS console and select the Properties for the Web application. On the Directory tab, click the Remove button. This will prevent access to the Web application and allow you to kill any remaining processes accessing the ASPState database. Once the processes are gone, uninstallation should completely successfully. Be sure to go back to the IIS console and click the Create button to restore the Web application to normal working order if you previously clicked the Remove button.

Version 1.0 of the .NET Framework does not provide a script for creating an ASPState database that maintains state persistently. However, Microsoft Knowledge Base article 311209 does provide a link for downloading InstallPersistentSqlState.sql and UninstallPersistentSqlState.sql. The InstallPersistentSqlState.sql script causes the session state data to be stored in permanent tables in ASPState instead of temporary tables in tempdb.

The .NET Framework provides both InstallPersistentSqlState.sql and InstallSqlState.sql. The Framework scripts are found in the %SYSTEMROOT%\Microsoft.NET\Framework\v1.1.4322 folder. Although the 1.0 and 1.1 versions of InstallPersistentSqlState.sql accomplish the same thing, they are different. For SQL Server 2000 and above, the 1.1 version creates the ASPState stored procedures using GETUTCDATE instead of GETDATE. The 1.0 version always uses GETDATE. You can use the Framework version 1.1 script to create a database for an application using the Framework version 1.0.

If you specify integrated security in the web.config file, you will have to create a server login for the ASPNET user and then make the login a user in the ASPState database. You will also have to grant permissions to the ASPNET user to use database objects. If you do not store state persistently, the ASPNET user must be granted permissions to use state management objects in tempdb. The prudent approach is to grant no more permissions than are absolutely necessary. Here are the permissions I granted after executing the Version 1.0 InstallSqlState.sql script:

USE masterGOEXECUTE sp_grantlogin [DBAZINE\ASPNET]GO USE ASPState GO EXECUTE sp_grantdbaccess [DBAZINE\ASPNET] GRANT EXECUTE on TempGetAppId to [DBAZINE\ASPNET] GRANT EXECUTE on TempGetStateItemExclusive to [DBAZINE\ASPNET] GRANT EXECUTE on TempInsertStateItemShort to [DBAZINE\ASPNET] GO USE tempdb — remove this if using persistent state GO — remove this if using persistent state EXECUTE sp_grantdbaccess [DBAZINE\ASPNET] — remove this if persistent state GRANT SELECT on ASPStateTempApplications to [DBAZINE\ASPNET] GRANT INSERT on ASPStateTempApplications to [DBAZINE\ASPNET] GRANT SELECT on ASPStateTempSessions to [DBAZINE\ASPNET] GRANT INSERT on ASPStateTempSessions to [DBAZINE\ASPNET] GRANT UPDATE on ASPStateTempSessions to [DBAZINE\ASPNET] GO

If you use the InstallPersistentSqlState.sql, remove the three lines as indicated above.

Consider the grants shown above as a starting point for creating your own script appropriate for your environment.

Conclusion
ASP.NET offers two simple solutions to session state management in a Web farm. Only SQL Server offers persistent state management. A dedicated session state server does not offer persistent state management, but does not require the creation of a database (one more thing for the DBA to administer). The value of persistent state has to be weighed carefully. Maintaining session state persistently is useful only if the SQL Server can be brought back up within the session state timeout specified in the web.config. For those situations where using a SQL Server as a state server makes sense, ASP.NET makes it easy.
Read More

Friday, September 4, 2009

What is serialization in .NET? What are the ways to control serialization

Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.
• Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the clipboard. You can serialize an object to a stream, disk, memory, over the network, and so forth. Remoting uses serialization to pass objects "by value" from one computer or application domain to another.
• XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data. Because XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is an open standard, which makes it an attractive choice.
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code.
Read More

What is portable executable (PE)

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR. The specification for the PE/COFF file formats is available at
Read More

Can I write IL programs directly

Yes.
Following Example is written by Rajesh Rolen:-

.assembly MyAssembly {}
.class MyApp {
.method static void Main() {
.entrypoint
ldstr "Hello, IL!"
call void System.Console::WriteLine(class System.Object)
ret
}
}
Just put this into a file called hello.il, and then run ilasm hello.il. An exe assembly will be generated.
Read More

What is MSIL, IL

When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.
Read More

What is patindex and charindex in SQL

Patindex: Returns the string position of the first occurrence of pattern
Ex: Select patindex(‘%o%’, ‘Microsoft’)
Ans: 5. Note: % is must
Charindex: Same as patindex but you can specify the string position.
Ex: charindex ( Expression1, Expression2 [ , start_location])
Read More

What is Stuff in SQL server 2000

Specify length of characters and inserts another set of characters at a specified starting point.
Stuff(char_exp, start, length, char_exp[ New ] )
Ex: stuff(‘abcdef’, 2, 3 ‘ijklm’)
Ans: aijklmdef
Read More

What exactly happens when ASPX page is requested from Browser


Following are the steps which occur when we request a ASPX page :-
* The browser sends the request to the webserver.let’s assume that the webserver
at the other end is IIS.
* Once IIS receives the request he looks on which engine can serve this request.
When I mean engine means the DLL who can parse this page or compile and
send a response back to browser. Which request to map to is decided by file
extension of the page requested.
Depending on file extension following are some mapping
* .aspx, for ASP.NET Web pages,
* .asmx, for ASP.NET Web services,
* .config, for ASP.NET configuration files,
* .ashx, for custom ASP.NET HTTP handlers,
* .rem, for remoting resources
* Etc
You can also configure the extension mapping to which engine it can route by using the
IIS engine.

Example a ASP page will be sent to old classic ASP.DLL to compile. While .ASPX pages
will be routed to ASP.NET engine for compilation.
* As this book mainly will target ASP.NET we will look in to how ASP.NET
pages that is ASPX pages generation sequence occurs. Once IIS passes the
request to ASP.NET engine page has to go through two section HTTP module
section and HTTP handler section. Both these section have there own work
to be done in order that the page is properly compiled and sent to the IIS.
HTTP modules inspect the incoming request and depending on that they can
change the internal workflow of the request. HTTP handler actually compiles
the page and generates output. If you see your machine.config file you will see
following section of HTTP modules



type="System.Web.Security.WindowsAuthenticationModule" />
type="System.Web.Security.FormsAuthenticationModule" />
type="System.Web.Security.PassportAuthenticationModule" />
type="System.Web.Security.UrlAuthorizationModule" />
type="System.Web.Security.FileAuthorizationModule" />
>

The above mapping shows which functionality is handled by which Namespace. Example
FormsAthuentication is handled by “System.Web.Security.FormsAuthenticationModule”.
If you look at the web.config section HTTP module is where authentication and
authorization happens.
Ok now the HTTP handler is where the actual compilation takes place and the output is
generated.Following is a paste from HTTP handler section of WEB.CONFIG file.







...

* Depending on the File extension handler decides which Namespace will
generate the output. Example all .ASPX extension files will be compiled by
System.Web.UI.PageHandlerFactory
* Once the file is compiled it send back again to the HTTP modules and from
there to IIS and then to the browser.
Read More

How do we enable tracing

<%@ Page Trace="true" %>
Read More

What is Tracing in ASP.NET

Tracing allows us to view in detail how the code was executed.
Read More

Show the entire validation error message in a message box on the client side

In validation summary set “ShowMessageBox” to true.
Read More

How to disable client side script in validators

Set EnableClientScript to false.
Read More

Which JavaScript file is referenced for validating the validators at the client side

WebUIValidation.js javascript file installed at “aspnet_client” root IIS directory is used to validate the validation controls at the client side
Read More

If you have client side validation is enabled in your Web page , Does that mean server side code is not run

When client side validation is enabled server emit’s JavaScript code for the custom
validators. But note that does not mean that server side checks on custom validators do
not execute. It does this two time redundant check. As some of the validators do not
support client side scripting.
Read More

How can we check if all the validation control are valid and proper

Using the Page.IsValid() property you can check whether all the validation are done.
Read More

How can we force all the validation control to run

Page.Validate
Read More

Do session use cookies

cookie enabled and cookieless sessions.
By default session uses cookies.

if you do not want to use cookies to store session then add/modify the session section in the web.config to

Read More

What order in which events of global.asax are triggered

They're triggered in the following order:
Application_BeginRequest
Application_AuthenticateRequest
Application_AuthorizeRequest
Application_ResolveRequestCache
Application_AcquireRequestState
Application_PreRequestHandlerExecute
Application_PreSendRequestHeaders
Application_PreSendRequestContent
<>
Application_PostRequestHandlerExecute
Application_ReleaseRequestState
Application_UpdateRequestCache
Application_EndRequest.
Read More

What are major events in GLOBAL.ASAX file

The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following events:

Application_Init: Fired when an application initializes or is first called. It's invoked for all HttpApplication object instances.

Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.

Application_Error: Fired when an unhandled exception is encountered within the
application.

Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.

Application_End: Fired when the last instance of an HttpApplication class is destroyed. It's fired only once during an application's lifetime.

Application_BeginRequest: Fired when an application request is received. It's the first event fired for a request, which is often a page request (URL) that a user enters.

Application_EndRequest: The last event fired for an application request.

Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework
begins executing an event handler like a page or Web service.

Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is
finished executing an event handler.

Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends
HTTP headers to a requesting client (browser).

Application_PreSendContent: Fired before the ASP.NET page framework sends content
to a requesting client (browser).

Application_AcquireRequestState: Fired when the ASP.NET page framework gets the
current state (Session state) related to the current request.

Application_ReleaseRequestState: Fired when the ASP.NET page framework completes
execution of all event handlers. This results in all state modules to save their current state data.

Application_ResolveRequestCache: Fired when the ASP.NET page framework completes
an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.

Application_UpdateRequestCache: Fired when the ASP.NET page framework completes
handler execution to allow caching modules to store responses to be used to handle
subsequent requests.

Application_AuthenticateRequest: Fired when the security module has established the
current user's identity as valid. At this point, the user's credentials have been validated.

Application_AuthorizeRequest: Fired when the security module has verified that a user
can access resources.

Session_Start: Fired when a new user visits the application Web site.

Session_End: Fired when a user's session times out, ends, or they leave the application Web site.
Read More

Difference between ASP and ASP.NET

ASP.NET new feature supports are as follows :-
Better Language Support
$. New ADO.NET Concepts have been implemented.

$. ASP.NET supports full language (C# , VB.NET,C++) and not simple scripting
like VBSCRIPT..
Better controls than ASP
$. ASP.NET covers large set’s of HTML controls..

$. Better Display grid like Datagrid , Repeater and datalist.Many of the display
grid have paging support.

Controls have event supports

$. All ASP.NET controls support events.

$. Load, Click and Change events handled by code makes coding much simpler
and much better organized.

Compiled Code

The first request for an ASP.NET page on the server will compile the ASP.NET code and
keep a cached copy in memory. The result of this is greatly increased performance.
Better Authentication Support
ASP.NET supports forms-based user authentication, including cookie management and
automatic redirecting of unauthorized logins. (You can still do your custom login page
and custom user checking).
User Accounts and Roles
ASP.NET allows for user accounts and roles, to give each user (with a given role) access
to different server code and executables.
High Scalability
$. Much has been done with ASP.NET to provide greater scalability.

$. Server to server communication has been greatly enhanced, making it possible
to scale an application over several servers. One example of this is the ability
to run XML parsers, XSL transformations and even resource hungry session
objects on other servers.
Easy Configuration

$. Configuration of ASP.NET is done with plain text files.

$. Configuration files can be uploaded or changed while the application is running.
No need to restart the server. No more metabase or registry puzzle.
Easy Deployment
No more server restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.
Read More

How will decide the design consideration to take a Datagrid , datalist or repeater

Many make a blind choice of choosing datagrid directly , but that's not the right way.
Datagrid provides ability to allow the end-user to sort, page, and edit its data.But it
comes at a cost of speed.Second the display format is simple that is in row and columns.
Real life scenarios can be more demanding that With its templates, the DataList provides more control over the look and feel of the displayed data than the DataGrid.It offers better performance than datagrid Repeater control allows for complete and total control. With the Repeater, the only HTML emitted are the values of the databinding statements in the templates along with the HTML markup specified in the templates—no "extra" HTML is emitted, as with the DataGrid and DataList. By requiring the developer to specify the complete generated HTML markup, the Repeater often requires the longest development time.But repeater does not provide editing features like datagrid so everything has to be coded by programmer . However, the Repeater does boast the best performance of the three data Web controls.
Repeater is fastest followed by Datalist and finally datagrid.
Read More

How can we format data inside DataGrid

Use the DataFormatString property
Read More

What’s the method to customize columns in DataGrid

Use the template column.
Read More

Difference between Datagrid , Datalist and repeater From performance point of view

Repeater is fastest followed by Datalist and finally datagrid.
Read More

What’s difference between Datagrid , Datalist and repeater

A Datagrid, Datalist and Repeater are all ASP.NET data Web controls.
They have many things in common like DataSource Property , DataBind Method
ItemDataBound and ItemCreated.
When you assign the DataSource Property of a Datagrid to a DataSet then each DataRow
present in the DataRow Collection of DataTable is assigned to a corresponding
DataGridItem and this is same for the rest of the two controls also.But The HTML code
generated for a Datagrid has an HTML TABLE element created for the particular
DataRow and its a Table form representation with Columns and Rows.
For a Datalist its an Array of Rows and based on the Template Selected and the
RepeatColumn Property value We can specify how many DataSource records should
appear per HTML < table > row. In short in datagrid we have one record per row, but in datalist we can have five or six rows per row.
For a Repeater Control,The Datarecords to be displayed depends upon the Templates
specified and the only HTML generated is the due to the Templates.
In addition to these , Datagrid has a in-built support for Sort,Filter and paging the Data ,which is not possible when using a DataList and for a Repeater Control we would require to write an explicit code to do paging.
Read More

Wednesday, September 2, 2009

.NET framework overview 1

Has own class libraries. System is the main namespace and all other namespaces are subsets of this.

It has CLR(Common language runtime, Common type system, common language specification)

All the types are part of CTS and Object is the base class for all the types.

If a language said to be .net complaint, it should be compatible with CTS and CLS.

All the code compiled into an intermediate language by the .Net language compiler, which is nothing but an assembly.

During runtime, JIT of CLR picks the IL code and converts into PE machine code and from there it processes the request.
CTS, CLS, CLR
Garbage Collection
Dispose, finalize, suppress finalize, Idispose interface
Assemblies, Namespace

Assembly is a collection of class/namespaces. An assembly contains Manifest, Metadata, Resource files, IL code
Com interoperability, adding references, web references
Database connectivity and providers
Application Domain
Read More

8. Difference Between Global.asax and web.config file

Global.asax: This file maintain the events. Suppose you want initialize a variable in a particular event means you can assign. User can declare global variable in this file.

Web.Config: This file maintain the Security measurement. We can connect database globally. This file is fully XML format.
Read More

What method do you use to explicitly kill a user Session

by using Session.Abandon we can kill a user session.

Abandon
The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.
Syntax Session.Abandon

Remarks
When the Abandon method is called, the current Session object is queued for deletion, but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to Abandon, but not in any subsequent Web pages.
For example, in the following script, the third line prints the value Mary. This is because the Session object is not destroyed until the server has finished processing the script.
<%
Session.Abandon
Session("MyName") = "Mary"
Reponse.Write(Session("MyName"))
%>

Contents.Remove
The Remove method deletes a specific item from the Session object's Contents collection.
Syntax
Session.Contents.Remove( Item|Index )

Parameter
Item - The name of the member to remove from the collection.
Index - The index entry for the member to remove from the collection.

Remarks
The Contents.Remove method takes either a string or an integer as an input parameter. If the input parameter is a string, the method will search the contents collection for an item with that name and remove it. If the input parameter is an integer, the method counts that number of items from the start of the collection, and removes the corresponding item.

Example
The following example adds and removes a variable called myName to the Session.Contents collection.
<%
Session("myName") = " "
Session.Contents.Remove("myName")
%>

Contents.RemoveAll
The RemoveAll method deletes all items that have been added to the Session object's Contents collection.
Syntax
Session.Contents.RemoveAll ()

Example
The following example removes all items that have been added to the Session.contents collection:
<%Session.Contents.RemoveAll()%>
Read More

Explain Server side code and Client side code

Server side code : That code runs at server side and use resources of server like database access. Example of server side languages: - ASP.NET, PHP, JSP.

Client side code : The code which uses client side resources and That code is like VB / Java scripts. It is to use validation purpose as well as for client side programming purpose.
Read More

What is Multi-threading

Multi-threading forms subset of Multi-tasking instead of having to switch between programs this feature switches between different parts of the same program.Example you are writing in word and at the same time word is doing a spell check in background.

Multi-tasking :- Its a feature of modern operating systems with which we can run multiple programs at
same time example Word,Excel etc.
Read More

What is a satellite assembly

In multilingual application in .NET to support multilingual functionality you can have modules which are customized for localization.These assemblies are called as satellite assemblies. You can distribute these assemblies separately than the core modules.
Read More

What is difference between VB.NET and C#

Well this is the most debatable issue in .NET community and people treat there languages like religion.
Its a subjective matter which language is best.Some like VB.NET’s natural style and some like professional and terse C# syntaxes.Both use the same framework and speed is also very much equivalents .
But still lets list down some major differences between them :-

Advantages VB.NET :-
1. Has support for optional parameters which makes COM interoperability much easy.

2. With Option Strict off late binding is supported.Legacy VB functionalities can be
used by using Microsoft.VisualBasic namespace.

3. Has the WITH construct which is not in C#.

4. The VB.NET part of Visual Studio .NET compiles your code in the background.
While this is considered an advantage for small projects, people creating very large
projects have found that the IDE slows down considerably as the project gets larger.
Advantages of C#

5. XML documentation is generated from source code but this is now been incorporated
in Whidbey.

6. Operator overloading which is not in current VB.NET but is been introduced in
Whidbey.

7. The using statement, which makes unmanaged resource disposal simple.

8. Access to Unsafe code. This allows pointer arithmetic etc, and can improve
performance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies).This is the major difference that you can access unmanaged code in C# and not in VB.NET.
Read More

What is concept of Boxing and Unboxing

Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type.Boxing is process in which a object instances created and copying value types value in to that instance.
Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location.
Below is sample code of boxing and unboxing where integer data type is converted in to object and then vice versa.

Dim x As Integer
Dim y As Object
x = 10
‘ boxing process
y = x
‘ unboxing process
x = y
Read More

What are Value types and Reference types

Value types directly contain their data are either allocated on the stack or allocated in-line in a structure.
Reference types store a reference to the value's memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types.
Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable.All types derive from the System.Object base type.
Read More

Can we force garbage collector to run

System.GC.Collect() forces garbage collector to run.This is not recommended but can be used if
situations arises.
Read More

What is garbage collection

Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... laziness ( Remember in VB6 where one of the good practices is to set object to nothing).

CLR automatically releases objects when they are no longer referenced and in use.

CLR runs on non-deterministic to see the unused objects and cleans them.

One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. Therefore, we should not put code into a class destructor to release resources.

so. The object which are not currently in use and their is no chances of it to be used in future, then GC can release its memory, but its not guaranteed that GC will relase the memory as soon as it is applicable to GC. but when the remain less in that situation it is guarantee that GC will release the memory.

we can run GC maiually:- System.GC.Collect() forces garbage collector to run.This is not recommended but can be used if
situations arises
Read More

What is concept of strong names

Strong name is similar to GUID(It is supposed to be unique in space and time) in COM
components.Strong Name is only needed when we need to deploy assembly in GAC.Strong
Names helps GAC to differentiate between two versions.Strong names use public key cryptography
(PKC) to ensure that no one can spoof it.PKC use public key and private key concept.
Following are the step to generate a strong name and sign a assembly :-

1. Go to “Visual Studio Command Prompt”.


2. After you are in command prompt type sn.exe -k “c:\test.snk”.

3. After generation of the file you can view the SNK file in a simple notepad.

4. After the SNK file is generated its time to sign the project with this SNK file.

5. Click on project -- properties and the browse the SNK file to the respective
folder and compile the project.
Read More

What is GAC

GAC (Global Assembly Cache) is used where shared .NET assembly reside.GAC is used in the following situations :-

1. If the application has to be shared among several application.

2. If the assembly has some special security requirements like only administrators
can remove the assembly.If the assembly is private then a simple delete of
assembly the assembly file will remove the assembly.

Note:-Registering .NET assembly in GAC can lead to the old problem of DLL hell.
Where COM version was stored in central registry.So GAC should be used when
absolutely necessary.
Read More

Is versioning applicable to private assemblies

Versioning concept is only applicable to global assembly cache (GAC) as private assembly lie in there individual folders.
Read More

Where is version information stored of a assembly

Version information is stored in assembly in manifest.
Read More

What is Manifest

Assembly metadata is stored in Manifest.Manifest contains all the metadata needed to do the following things:-

1. Version of assembly

2. Security identity

3. Scope of the assembly

4. resolve references to resources and classes.

5. The assembly manifest can be stored in either a PE file (an .exe or .dll) with
Microsoft intermediate language (MSIL) code or in a stand-alone PE file that
contains only assembly manifest information.
Read More

If you want to view a Assembly how to you go about it

When it comes to understanding of internals nothing can beat ILDASM.ILDASM basically converts the whole exe or dll in to IL code.To run ILDASM you have to go to "C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin". Note that i had v1.1 you have to probably change it depending on the type of framework version you have.
If you run IDASM.EXE from the path you will be popped with the IDASM exe program as
shown in figure ILDASM.Click on file and browse to the respective directory for the DLL whose assembly you want to view.After you select the DLL you will be popped with a tree view details of the DLL as shown in figure ILDASM.On double clicking on manifest you will be able to view details of assembly , internal IL code etc.
Read More

What is Difference between NameSpace and Assembly

Following are the differences between namespace and assembly :

1. Assembly is physical grouping of logical units. Namespace logically groups
classes.

2. Namespace can span multiple assembly.
Read More

What is NameSpace

Namespace has two basic functionality :-

1. NameSpace Logically group types.Example System.Web.UI logically groups
our UI related features.

2. In Object Oriented world may times its possible that programmers will use the
same class name.By qualifying NameSpace with classname this collision can
be removed.
Read More

What are different types of Assembly

There are two types of assembly Private and Public assembly.

1. A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A

2. shared assembly is normally stored in the global assembly cache, which is a repository of assemblies
maintained by the .NET runtime. Shared assemblies are usually libraries of code which many
applications will find useful, e.g. Crystal report classes which will be used by all application for
Reports.
Read More

What is a Assembly

1. Assembly is unit of deployment like EXE or a DLL.

2. An assembly consists of one or more files (dlls, exe’s, html files etc.), and
represents a group of resources, type definitions, and implementations of those
types. An assembly may also contain references to other assemblies. These
resources, types and references are described in a block of data called a manifest.
The manifest is part of the assembly, thus making the assembly self-describing.

3. An assembly is completely self-describing.An assembly contains metadata
information, which is used by the CLR for everything from type checking and
security to actually invoking the components methods.As all information is in
assembly itself it is independent of registry.This is the basic advantage as
compared to COM where the version was stored in registry.

4. Multiple versions can be deployed side by side in different folders. These
different versions can execute at the same time without interfering with each
other.Assemblies can be private or shared. For private assembly deployment,the
assembly is copied to the same directory as the client program that references
it.No registration is needed, and no fancy installation program is required.
When the component is removed, no registry cleanup is needed,and no uninstall
program is required. Just delete it from the hard drive.

5. In shared assembly deployment, an assembly is installed in the Global Assembly
Cache (or GAC). The GAC contains shared assemblies that are
globally accessible to all .NET applications on the machine.
Read More

What is a Managed Code

Managed code runs inside the environment of CLR. i.e. .NET runtime.
In short all IL are managed code.
But if you are using some third party software example VB6 or VC++ component they are
unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language.
Read More

What is a CLS(Common Language Specification)

This is a subset of the CTS which all .NET languages are expected to support.It was always a dream of microsoft to unite all different languages in to one umbrella and CLS is one step towards that.Microsoft has defined CLS which are nothing but guidelines that language to follow, so that it can communicate with other .NET languages in a seamless manner.
Read More

What is a CTS?

In order that two different languages can communicate Microsoft introduced Common Type System. For example in VB you have “Integer” and in C++ you have “long” these datatypes are not compatible so the interfacing between them is very complicated.
In order that two language communicate smoothly CLR has CTS (Common Type System).

So “Integer” datatype in VB6 and “int” datatype in C++ will convert it to System.int32 which is datatype of CTS.
Read More

What is a CLR and what is use of it in .NET

framework.All Languages have runtime and its the responsibility of the runtime to take care of
the code execution of the program.For example VC++ has MSCRT40.DLL,VB6 has
MSVBVM60.DLL , Java has Java Virtual Machine etc. Similarly .NET has CLR.Following are the
responsibilities of CLR
1. Garbage Collection :- CLR automatically manages memory thus eliminating
memory leakes. When objects are not referred GC automatically releases those
memory thus providing efficient memory management.
2. Code Access Security :- CAS grants rights to program depending on the security
configuration of the machine.Example the program has rights to edit or create
a new file but the security configuration of machine does not allow the program
to delete a file.CAS will take care that the code runs under the environment of
machines security configuration.
3. Code Verification :- This ensures proper code execution and type safety while
the code runs.It prevents the source code to perform illegal operation such as
accessing invalid memory locations etc.
4. IL( Intermediate language )-to-native translators and optimizer’s :- CLR uses
JIT compiler and compiles the IL code to machine code and then executes. CLR also
determines depending on platform what is optimized way of running the IL
code.
Read More
Powered By Blogger · Designed By Seo Blogger Templates