Thursday, July 10, 2008

AsP.Net Questions V

*Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config.


*How do you handle data concurrency in .NET ?
One of the key features of the ADO.NET DataSet is that it can be a self-contained and disconnected data store. It can contain the schema and data from several rowsets in DataTable objects as well as information about how to relate the DataTable objects-all in memory. The DataSet neither knows nor cares where the data came from, nor does it need a link to an underlying data source. Because it is data source agnostic you can pass the DataSet around networks or even serialize it to XML and pass it across the Internet without losing any of its features. However, in a disconnected model, concurrency obviously becomes a much bigger problem than it is in a connected model.
In this column, I’ll explore how ADO.NET is equipped to detect and handle concurrency violations. I’ll begin by discussing scenarios in which concurrency violations can occur using the ADO.NET disconnected model. Then I will walk through an ASP.NET application that handles concurrency violations by giving the user the choice to overwrite the changes or to refresh the out-of-sync data and begin editing again. Because part of managing an optimistic concurrency model can involve keeping a timestamp (rowversion) or another type of flag that indicates when a row was last updated, I will show how to implement this type of flag and how to maintain its value after each database update.

Windows Services for VB.NET Developers

A Windows Service is an application that runs outside of any desktop session. It can run automatically when Windows starts up, before any users log in. Alternatively, it can be started up by some other app via the Windows Service Control Manager (SCM - pronounced "scum"). Not to be confused with a Web Service, which runs a particular protocol and serves up XML to remote machines, a Windows Service is a basic building block of the Windows operating system. An out-of-the-box install of Windows XP has more than 80 Windows Services installed (necessary?). Outside of a Microsoft environment, this type of program is commonly referred to as a ‘daemon’, or more accurately, a ‘dragon’ (which appeals far more to the author than any other terminology). It runs in a security context independent of any logged on user—configured in the Services Manager (right-click My Computer, select Manage, expand Services and Applications, then Services) where you’ll also find its start/stop controls.

Visual Studio .NET makes it very simple to create and install Windows Services: just select the Windows Service template when starting a new project. In this article you’ll see the (very little) code needed to make this service work and all the Administrative tasks you’ll need to perform to get it running. You’ll build a project called “Empty Service” that can be used as a template to build all kinds of Windows Services. You then just add your own business class to perform the activity you need.

A Windows Service exposes two main commands: Start and Stop. It begins work when it receives a Start command from the SCM. It is therefore in the OnStart method that you will put code to execute whatever work it is you want the service to perform. The Service can support other functions optionally, such as Pause and Continue, or Custom Commands. These too respond to controls received from the SCM. You want to avoid any desktop interaction since your service will run in a security session unattached to any particular user session (e.g. no message boxes, prompts, etc.).

As the Start command is only called once, the Service itself must implement a mechanism to periodically “wake the dragon”. The simplest way to do this is to drop a Timer component on the Service designer, and call its Start and Stop methods from the OnStart and OnStop methods of your Service. However, this gives you little control over process creation and you end up with many threads running at a time. This article shows you how to implement a single “worker” thread which executes in a loop only when the previous iteration is complete—hence program overlap is avoided.

SOAP is a simple XML based protocol to let applications exchange information over HTTP.

What is SOAP?

SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP will be developed as a W3C standard
It is important for application development to allow Internet communication between programs.

Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.

A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this.

SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.


Satellite assemblies is the default way to localize .NET applications. To make form localizable set form's Localizable property to true.
You can do it using Properties Window in Visual Studio.
You can specify language for your application or use the same culture as specified as that set in Control Panel:


LOCALIZATION : means "process of translating resources for a specific culture", and


GLOBALIZATION : means "process of designing applications that can adapt to different cultures".


The future of the Web Services
The future looks bright for the Web Service technology. Microsoft is not alone in the race for Web Service technology. Sun and IBM are very interested. There are SOAP toolkits available for Apache and Java Web servers. I believe Web Services needs a bit of work, especially the Web Service discovery process. It is still very primitive.

On a positive note, Web Services have the potential to introduce new concepts to the Web. One I refer to as "pay per view" architecture. Similar to pay-TV, we can build Web sites that can generate revenue for each request a user sends (as opposed to a flat, monthly subscription). In order to get some data, we can sometimes pay a small fee. Commercially this could be handy for a lot of people.


Multiple inheritance is not supported as a built in feature in .NET. However just like JAVA we have the option of implementing multiple
inheritance using interfaces.An interface can inherit methods and attributes from different classes regardless of their position in the
inheritance hierarchy.Furthermore any subclass that IMPLEMENTS an interface has to implement all methods and attribute for the interface.
The methods or attributes that are not being used by the class implementing an interface will be declared as abstract methods.In short
when a subclass implements an interface it comes into a contract with the the Interface that it will implement all methods and attributes
of the interface.
How does output caching work in ASP.NET?

Output caching is a powerful technique that increases request/response throughput by caching the content generated from dynamic pages. Output caching is enabled by default, but output from any given response is not cached unless explicit action is taken to make the response cacheable.

To make a response eligible for output caching, it must have a valid expiration/validation policy and public cache visibility. This can be done using either the low-level OutputCache API or the high-level @ OutputCache directive. When output caching is enabled, an output cache entry is created on the first GET request to the page. Subsequent GET or HEAD requests are served from the output cache entry until the cached request expires.

The output cache also supports variations of cached GET or POST name/value pairs.

The output cache respects the expiration and validation policies for pages. If a page is in the output cache and has been marked with an expiration policy that indicates that the page expires 60 minutes from the time it is cached, the page is removed from the output cache after 60 minutes. If another request is received after that time, the page code is executed and the page can be cached again. This type of expiration policy is called absolute expiration - a page is valid until a certain time.

Q. What is ODBC connection pooling?

A. Connection pooling is one the new features introduced in ODBC 3.0. Connection pooling enables an ODBC application to reuse a connection from a pool of connections. Once a connection has been created and placed in the pool, an ODBC application can reuse the same driver and the connection within the same shared environment (henv) without performing the complete connection process. However, a connection can never be reused between different henv or different drivers.
2. Q. Can I use connection pooling with 2.x ODBC drivers?

A. Connection pooling is implemented in the ODBC driver manager version 3.0 or later. The driver version does not matter.
3. Q. Can I enable connection pooling with the Microsoft Access driver because the connection pooling is implemented in the driver manager?

A. You can enable connection pooling for Microsoft Access driver. Microsoft Access uses Jet, and Jet is thread safe starting from Jet 4.0. From MDAC 2.1 and later, you can have connection pooling for Access ODBC driver.
4. Q. How do I enable connection pooling in an ODBC application?

A. An ODBC application can call SQLSetEnvAttr with the SQL_ATTR_CONNECTION_POOLING attribute to enable connection pooling. For more information about how to enable connection pooling in an ODBC application, please see the following article in the Microsoft Knowledge Base:
164221 ( How to Enable Connection Pooling in an ODBC Application
5. Q. How do I enable connection pooling if the application is written in Visual Basic?

A. A Visual Basic or ODBC application can call the SQLSetEnvAttr function to enable connection pooling. Connection pooling is a process-level attribute, so any subsequent connection made through the ODBC driver manager in the Visual Basic application will use connection pooling. A Visual Basic application can use the function declaration and code to enable connection pooling.

How do I clear out the connections in the pool?

A. How long a connection remains in the pool depends on the CPTimeout property of the ODBC driver. When the timeout expires, the connection will be closed and removed from the pool. The ODBC application can use SQLConfigDriver to change the value of CPTimeout, and this value applies to all the ODBC applications that are using the specified ODBC driver. The default value for the CPTimeout is 60 seconds.

What is an interface and what is an abstract class? Please, expand by examples of using both. Explain why.
What is serialization, how it works in .NET?
What should one do to make class serializable?
What exactly is being serialized when you perform serialization?

Tell me about 6h4 methods you have used to perform serialization.
Did you work with XML and XSL Transformations?
What methods and what for did you use to work with XML?
What is the purpose of reserved word “using” in C#?
How does output caching work in ASP.NET?
What is connection pooling and how do you make your application use it?
What are different methods of session maintenance in ASP.NET?
What is Viewstate?
Can any object be stored in a Viewstate?
What should you do to store an object in a Viewstate?
Explain how Viewstate is being formed and how it’s stored on client.
Explain control life cycle, mind event order.
What do you know about ADO.NET’s objects and methods?
Explain DataSet.AcceptChanges and DataAdapter.Update methods.
Assume you want to update a record in the database using ADO.NET. What necessary steps you should perform to accomplish this?
How to retreive the value of last identity has been updated in a database (SQL Server)?
Interviewing at Microsoft? - Read employment practices and questions asked.

Explain the .NET architecture.
How many languages .NET is supporting now? - When .NET was introduced it came with several languages. VB.NET, C#, COBOL and Perl, etc. The site DotNetLanguages.Net says 44 languages are supported.
How is .NET able to support multiple languages? - a language should comply with the Common Language Runtime standard to become a .NET language. In .NET, code is compiled to Microsoft Intermediate Language (MSIL for short). This is called as Managed Code. This Managed code is run in .NET environment. So after compilation to this IL the language is not a barrier. A code can call or use a function written in another language.

How ASP .NET different from ASP? - Scripting is separated from the HTML, Code is compiled as a DLL, these DLLs can be executed on the server.
Resource Files: How to use the resource files, how to know which language to use?
What is smart navigation? - The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.
What is view state? - The web is stateless. But in ASP.NET, the state of a page is maintained in the in the page itself automatically. How? The values are encrypted and saved in hidden controls. this is done automatically by the ASP.NET. This can be switched off / on for a single control
Explain the life cycle of an ASP .NET page.
How do you validate the controls in an ASP .NET page? - Using special validation controls that are meant for this. We have Range Validator, Email Validator.
Can the validation be done in the server side? Or this can be done only in the Client side? - Client side is done by default. Server side validation is also possible. We can switch off the client side and server side can be done.
How to manage pagination in a page? - Using pagination option in DataGrid control. We have to set the number of records for a page, then it takes care of pagination by itself.
What is ADO .NET and what is difference between ADO and ADO.NET? - ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory database where in I can use relationships between the tables and select insert and updates to the database. I can update the actual database as a batch.

Delegate is commonly defined as a Type Safe Pointer. To better understand a Type-Safe pointer, let's see a how a callback function in C++/VC++ works.
The Callback function is normally implemented in the Business tier of a 3-tier architecture (of course there are exceptions to that).
Once the Business Logic component implements a particular functionality, say a complex arithmetic calculation, it informs a client that the
job was performed successfully. In order to inform the client, it needs an address of the function\method implemented in the client.
The address of a function is just a memory address; this address does not carry any information such as number of parameters, data type of each
parameter and its return value. Since the Callback function does not have any idea of the Method Signature it is going to call, in short,
it is not Type Safe.

However, Delegates provide the feature of Callback functions in a safe way. Taking the previous example, if the Business Logic finds that the function
signature implemented by the Client differs in terms of number of parameters or parameter types or return values as opposed to the method signature,
it is going to safely raise an error.

Using Delegates

Deligates Link
Virtual keyword
The virtual keyword allows polimorphism too. A virtual property or method has an implementation in the base class, and can be overriden in the derived classes.

To create a virtual member in C#, use the virtual keyword:
public virtual void Draw()

To create a virtual member in VB.NET, use the Overridable keyword:
Public Overridable Function Draw()

Setup -- Versus Deployment
Before you can understand the processes involved in setting up and deploying applications, you need to understand the difference between setup and deployment. A setup is an application or process that allows you to package up your application into an easy-to-deploy format, which then can be used to install the application on another machine. Deployment is the process of taking the application and installing it in on another machine, usually by using a setup application.


RecordSet is used in VB 6.0 and DataSet in VB.NET

RecordSet is operate in Connection Oriented Manner i.e. For Each Query and Each Record The Request goes to the database and after that user will get result.
In RecordSet we can use only one database for Data operations.
by Using DataSet
DataSet is operate in Disconnected Manner i.e unlike the Recordset we don't Need to send query for each record instead of it Dataset can retrive all the information at a time so it operates in disconnected manner and we can use more that one database for data retriving using dataset.

RecordSet is Required More time than DataSet For data retrival
DataSet is always Better than the RecordSet.

What is an Abstract class?

An abstract class is a special kind of class that cannot be instantiated.
So the question is why we need a class that cannot be instantiated? An abstract class
is only to be sub-classed (inherited from). In other words, it only allows other
classes to inherit from it but cannot be instantiated. The advantage is that it enforces
certain hierarchies for all the subclasses. In simple words, it is a kind of contract
that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface.
An interface has no implementation; it only has the signature or in other words,
just the definition of the methods without the body. As one of the similarities to Abstract
class, it is a contract that is used to define hierarchies for all subclasses or it
defines specific set of methods and their arguments. The main difference between them is
that a class can implement more than one interface but can only inherit from one abstract
class. Since C# doesn’t support multiple inheritance, interfaces are used to
implement multiple inheritance.

No comments: