<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Interview Questions and Answers</title>
	<link>http://oopsconcepts.com/interviewquestions</link>
	<description>.Net Interview Questions and Answers</description>
	<pubDate>Fri, 21 Dec 2007 10:45:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>ADO.Net 2.0 Mutiple Active Result Sets (MARS)</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=57</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=57#comments</comments>
		<pubDate>Fri, 21 Dec 2007 10:40:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.Net 2.0 Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=57</guid>
		<description><![CDATA[ADO.NET 2.0 Multiple Active Resut Sets per connection in Sql Server 2005 (MARS) FAQ
ADO.NET 2.0 Multiple Active Resut Sets per connection in Sql Server 2005 (MARS) FAQ
Q: What is MARS?
A: MARS is a new feature in ado.net 2.0 and Sql Server 2005 that allows for multiple forward only read only result sets.
EDIT There is a [...]]]></description>
			<content:encoded><![CDATA[<h2>ADO.NET 2.0 Multiple Active Resut Sets per connection in Sql Server 2005 (MARS) FAQ</h2>
<p>ADO.NET 2.0 Multiple Active Resut Sets per connection in Sql Server 2005 (MARS) FAQ<br />
Q: What is MARS?</p>
<p>A: MARS is a new feature in ado.net 2.0 and Sql Server 2005 that allows for multiple forward only read only result sets.</p>
<p>EDIT There is a great article on MARS up at the technet site. It is a must read for basic understanding of MARS. I am specially impressed with the &#8220;Transaction Semantics&#8221; section http://www.microsoft.com/technet/prodtechnol/sql/2005/marssql05.mspx</p>
<p>Q: What is MARS for an ado.net developer?</p>
<p>A: MARS allows you to avoid seeing the dreaded “There is already an open DataReader ..” exception when executing on separate SqlCommands associated with the same connection. You can have multiple SqlDataReaders open on a single connection (again, each reader must be started on a new SqlCommand) and you don’t have to worry about Transaction isolation level scope locks.</p>
<p>Q: So MARS allows for better performance right?</p>
<p>A: I would like to say no outright, it would make my life much easier. You are trading the expense of opening new connections (almost free with pooling) for the hidden expenses of using MARS (fairly high IMO) The truth is that in some scenarios you will see actual perf improvement by using MARS, mostly thanks to Session Pooling. These scenarios are somewhat contrived and I would highly recomend that you do not modfify existing code or write new ugly code just to attempt to improve performance with MARS.</p>
<p>Q: What does Session Pooling mean to a SqlClient ado.net developer?</p>
<p>A: It means that you should _NOT_ use more than 9 SqlCommands per connection, if you do you will be forcing us to create/dispose very very expensive SqlCommands and you will definitelly notice the performance drop.</p>
<p>Q: What is MARS for Sql Server?</p>
<p>A: This has been a thorn in our side for too long. Other databases have supported this functionality for a long time and this has been one of the most important customer requested features to our model. I wish that I could explain how hard it has been to enable this behavior (completely anathema to our implementation) and how proud I am that we have driven this feature to market. That said I am concerned that this feature is going to be misused.</p>
<p>Q: Can I get better performance by combining MARS with ASYNC?</p>
<p>A: IMO, no. In ASP.NET applications you will not get better performance with MARs, and on Winform applications you should not use ASYNC with callbacks (See ASYNC FAQ) I would not mix these two features expecting to get better performance.</p>
<p>Q: So if MARS is not for performance what is it good for?</p>
<p>A: I like to use MARS in two core scenarios, 1) When using MARS results in cleaner looking code and 2) when I am using Transactions and need to execute in the same isolation level scope.</p>
<p>Q: What is Session Pooling?</p>
<p>A: This question should ideally come after I have explained the hidden costs of MARS, for now let me just explain what it does and I will blog on this with more detail at a later time. If you understand how pooling works then you are familiar with the idea of not destroying a valuable resource just because the user decides to close or dispose it. In this case the SqlCommand has become a valuable resource because we have to associate it with a Sql Server 2005 batch to enable MARS functionality. Session Pooling keeps up to 9 of these valuable disposed SqlCommands in a pool and hands them out the next time you create a command associated with the same connection.</p>
<p>Q: When does using MARS result in cleaner looking code?</p>
<p>A: The quintessential MARS example involves getting a datareader from the server and issuing insert/delete/update statements to the database as you process the reader.</p>
<p>Q: What are the costs of using MARS?</p>
<p>A: There are a lot of hidden costs associated with this feature, costs in the client, in the network layer and in the server. On the client we run into an issue where creating a new batch is not free, we kind of work around this issue by pooling mars commands but it is still expensive if you don’t used the pooled functionality. On the network layer there is a cost associated with multiplexing the TDS buffer, opening too many batches can be more expensive than opening another connection. On the server all MARS batches run in the same scope, worst case scenario your queries will end up running in the order received.</p>
<p>Q: Can I disable MARS?</p>
<p>A: Yes and No, you can disable MARS with the connection string keyword “MultipleActiveResultSets=false”. Under the covers we still use MARS headers so we will still have some of the overhead associated with MARS. You will not get better performance if you disable MARS, this option was only added to allow the developer to enable backward compatibility with applications that depend on SqlClient throwing an exception when more than one Result Set is used.</p>
<p>Q: What about the transaction isolation level scope?</p>
<p>A: Same example above but you have a transaction active and you have placed locks on the database. Please note that this behavior was _completelly_ broken before MARS! If you try to fake MARS by opening a second connection under the covers (like native SqlOledb does) you are outside of the transaction scope of the original connection. This is imo the biggest win with this feature.</p>
<p>Q: So OleDb may fake MARS?</p>
<p>A: Unfortunately yes. In what has to be one of my least favorite “features” the SqlOledb native provider will fake the ability of having multiple active result sets by opening a separate non-pooled connection to the server when unable to provide real MARS behavior. What this really means is that your code may be opening and throwing away connections that can bring your server to its knees during heavy traffic.</p>
<p>Q: What providers/backends support MARS?</p>
<p>A: The only provider/backend combination that supports the MARS feature that I am talking about in this FAQ is SqlClient talking to Sql Server 2005.</p>
<p>Q: Does this mean that none of the other providers support multiple DataReaders?</p>
<p>A: No it doesn’t. The OracleClient managed provider supports multiple DataReaders against all versions of Oracle. The OleDb managed provider is MUCH more problematic. It fully supports multiple DataReaders when talking to Sql Server 2005 when using MDAC 9. (IMPORTANT) In all other cases the OleDb managed provider will FAKE the ability of having multiple active result sets.</p>
<p>Q: Wait a minute; in v1.1 I was not able to open multiple DataReaders with OleDb.</p>
<p>A: This was an artificial restriction on the client, we have removed this restriction going forward since OleDb with the latest version of MDAC will now support true MARS behavior.</p>
<p>Q: What does the removal of this client side restriction mean?</p>
<p>A: It means that you can now shoot yourself in the foot when using the managed OleDb provider. IMHO it means that you should ONLY use SqlClient to talk to Sql Server, the risk of running into this fake MARS behavior is too great. I have seen this “feature” (fake MARS) cost hundreds of thousands of dollars an hour in lost sales as the server was inundated with unnecessary non-pooled connection open requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=57</wfw:commentRss>
		</item>
		<item>
		<title>C# Interview Questions 5</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=56</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=56#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:33:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[C# Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=56</guid>
		<description><![CDATA[What are indexers? What are their advantages over arrays?
An indexer enables you to treat an object like an array.It helps you to acces the arrays in a class using the class name. Indexer enables you to use bracket notation ([]) with an object to set and get a value from an object.They encapsulate method calls [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are indexers? What are their advantages over arrays?</strong></font><font size="2" face="Geneva, Arial, Sans-serif"><strong><br />
</strong>An indexer enables you to treat an object like an array.It helps you to acces the arrays in a class using the class name. Indexer enables you to use bracket notation ([]) with an object to set and get a value from an object.They encapsulate method calls into more convenient representation of value access and value setting.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">public dataType this[int index]<br />
{<br />
  get<br />
  {</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">     //Code to get some value from a array</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">     if (index &lt; 0)<br />
                return &#8220;negative&#8221;;<br />
            else if (index &gt; max)<br />
                return &#8220;Infinity&#8221;;<br />
            else<br />
                return arr[index];<br />
      }<br />
  set<br />
  {</font><br />
<font size="2" face="Geneva, Arial, Sans-serif">     arr[index]=value;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">  }<br />
}    </font><br />
<font size="2" face="Geneva, Arial, Sans-serif">Indexers makes your code more readable and easier to understand.</font><font size="2" face="Geneva, Arial, Sans-serif">You can create mulltiple indexers for a class.  Signature of each indexer should be unique.  The signature of an indexer is considered as the number and types of its formal parameters return data type of the indexer is not part of signature.</font><font size="2" face="Geneva, Arial, Sans-serif">They help you to represent as array values which may have no similarities to arrays as internal representation.</font><font size="2" face="Geneva, Arial, Sans-serif">You are not limited to using integers as indexes. You can use strings to achieve the result used in the Hash class and many others. </font><font size="2" face="Geneva, Arial, Sans-serif">Use indexer only when the representation of the class data as multiple objects is proper. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How would you implement singleton pattern in C#?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Singleton Pattern Definition<br />
The Singleton pattern ensures that a class only has one instance and provides a global point of access to it from a well-known access point. The class implemented using this pattern is responsible for keeping track of its sole instance rather than relying on global variables to single instances of objects</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Often, this pattern is used to represent parts of the system that there can only be one of, like the file system or window manager. Or, parts of your application that there will only ever be one of.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">C# Implementation </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">1. The constructor should be private.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">2. Provide a static method, which returns an instance of the class.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">3. Use a static variable to check whether already one instance is created or not. if already an instance is there , returns a null</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">using System;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">class  SingleInstanceClass&lt;o:p&gt;&lt;/o:p&gt;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">{         <br />
private static SingleInstanceClass sic= null;   <br />
private static bool instanceFlag = false; <br />
private SingleInstanceClass()       <br />
   {          <br />
   }          </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">public static SingleInstanceClass Create()     <br />
    {     <br />
          if(! instanceFlag)         <br />
        { <br />
            sic = new SingleInstanceClass();    <br />
            instanceFlag = true;  <br />
            return sic;     <br />
         }<br />
         else    <br />
         {<br />
             return null;   <br />
          }         <br />
    }      </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">protected void Finalize()     <br />
    {     <br />
       instanceFlag = false; <br />
     }<br />
}</font><br />
<font size="2" face="Geneva, Arial, Sans-serif">class MyClient</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">{         <br />
    public static void Main()           <br />
      {   <br />
         SingleInstanceClass sic1,sic2;      <br />
         sic1 = SingleInstanceClass.Create();   <br />
         if(sic1 != null)   <br />
              Console.WriteLine(&#8221;OK&#8221;);<br />
         sic2 = SingleInstanceClass.Create();   <br />
         if(sic2 == null)   <br />
         Console.WriteLine(&#8221;NO MORE OBJECTS&#8221;);  <br />
      }<br />
}</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The above program returns a null value when try to create an object second time. But instead of returning null, it is possible to return already existing object ‘sic’ by changing ‘return null’ to ‘return sic’ in the above program.&lt;o:p&gt;&lt;/o:p&gt;</font></p>
<p><font size="2"><font face="Arial"><strong>What is native image cache?<br />
</strong>The native image cache is a reserved area of the global assembly cache. Once you create a native image for an assembly, the runtime automatically uses that native image each time it runs the assembly. You do not have to perform any additional procedures to cause the runtime to use a native image. Running Ngen.exe on an assembly allows the assembly to load and execute faster, because it restores code and data structures from the native image cache rather than generating them dynamically.<br />
 <br />
Important:<br />
A native image is a file containing compiled processor-specific machine code. Note that the native image that Ngen.exe generates cannot be shared across Application Domains. Therefore, you cannot use Ngen.exe in application scenarios, such as ASP.NET, that require assemblies to be shared across application domains.<br />
 <br />
Note   To run Ngen.exe, you must have administrative privileges</font></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is called sealed classes?Can we derive sealed classes?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Sealed classes are those classes which cannot be inherited / derived by any other classes. These Classes are used to restrict the user boundaries. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">In VB.Net you can create these classes using “NonInheritable” keyword.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How would you register javascript in ASP.NET through code behind?<br />
</strong>The common way to accomplish this is to use RegisterStartupScript and the RegisterClientScriptBlock methods of the Page class.<br />
 <br />
Page.RegisterStartupScript -<br />
This method adds JavaScript to the web form right before the ending &lt;/FORM&gt;tag.<br />
This wouls be best used when we want to initiate a javascript function when the page is loaded. It takes two parameters<br />
— the first being the key of the script and the<br />
&#8211;  the second being the script itself (represented as a string).<br />
 <br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
           &#8212;&#8211;<br />
           &#8212;&#8211;<br />
           Page.RegisterStartupScript(&#8221;UserScript&#8221;,<br />
                       &#8221; language=javascript&gt;&#8221; +<br />
                        &#8220;function HelloWorld() { alert(&#8217;Hello World&#8217;); }&lt;/SCRIPT&gt; &#8220;);<br />
          Button1.Attributes[&#8221;onclick&#8221;] = &#8220;HelloWorld()&#8221;;<br />
          &#8212;&#8211;<br />
          &#8212;&#8211;<br />
}<br />
 <br />
Page.RegisterClientScriptBlock -<br />
This method adds JavaScript to the web form, right after the </font></p>
<p>&lt;FORM runat=&#8221;server&#8221;&gt;<font size="2" face="Geneva, Arial, Sans-serif">declaration.  It also takes two parameters— the first being the key of the script and the second being the script itself (represented as a string).<br />
 <br />
The main difference between the two methods is that the RegisterStartupScript method places the JavaScript at the bottom of the ASP.NET page right before the closing </font>&lt;/FORM&gt;</p>
<p><font size="2" face="Geneva, Arial, Sans-serif">element while RegisterClientScriptBlock method places the JavaScript directly after the opening </font></p>
<p>&lt;FORM&gt;<font size="2" face="Geneva, Arial, Sans-serif">element in the page. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can we use win32api dlls in .net? Explain how?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">If you talk about win32dll they are written in unmanged code. PInvoke helps us to call unmanged code from manage code. It locate and invoke the code and marshal their arguments at run time. In C# we use DLLImport as attribute to call<br />
win32api dll.</font></p>
<p><strong>What is the difference between setting an object to null and calling dispose method of the object ?</strong></p>
<p><strong>E.g. Object obj = new Object(); </strong></p>
<p><strong>obj = null </strong></p>
<p><strong>obj.dispose() </strong></p>
<p>When we set any object to null, that means that object is subject to garbage collection. But we dont have any control when exactly garbage collector reclaim memory and resources from this object. So in case we have occupied some heavy resources in any object, its better to implement a Dispose() method. So on calling the dispose() method explicitly, we can free the resources.</p>
<p><strong>What is the difference between Constant and Readonly?</strong></p>
<p>&#8216;const&#8217;:<br />
Can&#8217;t be static.<br />
Value is evaluated at compile time.<br />
Initiailized at declaration only.<br />
&#8216;readonly&#8217;:<br />
Can be either instance-level or static.<br />
Value is evaluated at run time.<br />
Can be initialized in declaration or by code in the constructor.</p>
<p><strong>What benefit does your code receive if you decorate it with attributes demanding specific Security permissions? </strong></p>
<p>Following are the benefits of using attribute based declarative security , essentially all the relevant information is stored in the asssembly metadata on compilation and based on permissions of the calling code , CLR will make sure that application or assembly doesn&#8217;t even get loaded in case doesn&#8217;t have relevant permissions vis a vis Imperative security , where everything is checked in assembly code and assembly will invariably get loaded and executed before it checks for any such issue or lack of permissions .<br />
 <br />
So , benefits of Declarative security are :<br />
 <br />
1. Inducing efficiency as all relevant information is stored in the metadata .<br />
2. Cleaner code as security is not mixed with program logic it&#8217;s done cleanly using attributes .</p>
<p><font size="2" face="Arial"><strong>How do you define pointers in c#?</strong></font></p>
<p><font size="2" face="Arial">Pointers in C# are syntactically used in the same way as you would use in c/c++. The only thing that is important to note is that, all code that is going to use pointers or address of operators is unsafe in .NET world and thus has to be marked with an unsafe modifier or has to be enclosed in an &#8220;unsafe&#8221; block. E.g.<br />
unsafe modifer:-<br />
unsafe void someFuncA(int *x)<br />
{<br />
//&#8230;do something<br />
}<br />
 <br />
unsafe static void Main()<br />
{<br />
int j = 100;<br />
someFunc(&amp;j);<br />
}<br />
unsafe block:-<br />
 <br />
void someFunction()<br />
{<br />
int j = 10;<br />
unsafe<br />
{<br />
int* i = &amp;j;<br />
}<br />
}<br />
 <br />
Lastly, all source code which contains &#8220;unsafe&#8221; code has to be compiled with &#8220;/unsafe&#8221; compiler option.<br />
</font><font size="2" face="Arial"> <br />
<strong>Posted By : Sarang Datye [Microsoft MVP - Visual Basic]</strong></font></p>
<hr /><font size="2" face="Arial"><strong>Dated :- 30th May</strong></font></p>
<p><font size="2" face="Arial"><strong>What is shallow copying ? How does MemberWiseClone method work ?</strong></font></p>
<p><font size="2" face="Arial">A shallow copy creates a new instance of the same type as the original object, and then copies the nonstatic fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not; therefore, the reference in the original object and the reference in the clone point to the same object. In contrast, a deep copy of an object duplicates everything directly or indirectly referenced by the fields in the object.</font></p>
<p><font size="2" face="Arial">MemberwiseClone method, creates a new instance of the source object and then does a bit-by-bit copy of value types and for reference types only the reference is copied. As a result both the original object and the clone end-up pointing to the same objects that the original object refers. And this is exactly what a copy constructor in C++ does :)!<br />
 <br />
So, e.g. If X is the object in context and it reference objects Y and Z then a shallow copy A of X will refer to Y and Z!<br />
</font></p>
<p><font size="2" face="Arial"><font size="2" face="Arial"><strong>What is the difference between a Debug and Release build? Is there a significant speed difference?</strong></font></p>
<p><font size="2" face="Arial">The biggest difference between these is that:<br />
In a debug build the complete symbolic debug information is emitted to help while debugging applications and also the code optimization is not taken into account.<br />
While in release build the symbolic debug info is not emitted and the code execution is optimized.<br />
Also, because the symbolic info is not emitted in a release build, the size of the final executable is lesser than a debug executable.<br />
 <br />
One can expect to see funny errors in release builds due to compiler optimizations or differences in memory layout or initialization. These are ususally referred to as Release - Only bugs <img src='http://oopsconcepts.com/interviewquestions/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
 <br />
In terms of execution speed, a release executable will execute faster for sure, but not always will this different be significant.<br />
</font></p>
<p></font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=56</wfw:commentRss>
		</item>
		<item>
		<title>C# Interview Questions 4</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=55</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=55#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:27:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[C# Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=55</guid>
		<description><![CDATA[Explain the differences between Server-side and Client-side code? 
Server side code executes on the server.For this to occur page has to be submitted or posted back.Events fired by the controls are executed on the server.Client side code executes in the browser of the client without submitting the page.
e.g. In ASP.NET for webcontrols like asp:button the [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Explain the differences between Server-side and Client-side code? </strong><br />
Server side code executes on the server.For this to occur page has to be submitted or posted back.Events fired by the controls are executed on the server.Client side code executes in the browser of the client without submitting the page.<br />
e.g. In ASP.NET for webcontrols like asp:button the click event of the button is executed on the server hence the event handler for the same in a part of the code-behind (server-side code). Along the server-side code events one can also attach client side events which are executed in the clients browser i.e. javascript events.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How does VB.NET/C# achieve polymorphism?<br />
</strong>Polymorphism is also achieved through interfaces. Like abstract classes, interfaces also describe the methods that a class needs to implement. The difference between abstract classes and interfaces is that abstract classes always act as a base class of the related classes in the class hierarchy. For example, consider a hierarchy-car and truck classes derived from four-wheeler class; the classes two-wheeler and four-wheeler derived from an abstract class vehicle. So, the class &#8216;vehicle&#8217; is the base class in the class hierarchy. On the other hand dissimilar classes can implement one interface. For example, there is an interface that compares two objects. This interface can be implemented by the classes like box, person and string, which are unrelated to each other.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">C# allows multiple interface inheritance. It means that a class can implement more than one interface. The methods declared in an interface are implicitly abstract. If a class implements an interface, it becomes mandatory for the class to override all the methods declared in the interface, otherwise the derived class would become abstract.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Can you explain what inheritance is and an example of when you might use it?<br />
The savingaccount class has two data members-accno that stores account number, and trans that keeps track of the number of transactions. We can create an object of savingaccount class as shown below.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">        savingaccount s = new savingaccount ( &#8220;Amar&#8221;, 5600.00f ) ;<br />
From the constructor of savingaccount class we have called the two-argument constructor of the account class using the base keyword and passed the name and balance to this constructor using which the data member&#8217;s name and balance are initialised.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">We can write our own definition of a method that already exists in a base class. This is called method overriding. We have overridden the deposit( ) and withdraw( ) methods in the savingaccount class so that we can make sure that each account maintains a minimum balance of Rs. 500 and the total number of transactions do not exceed 10. From these methods we have called the base class&#8217;s methods to update the balance using the base keyword. We have also overridden the display( ) method to display additional information, i.e. account number.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Working of currentaccount class is more or less similar to that of savingaccount class.<br />
Using the derived class&#8217;s object, if we call a method that is not overridden in the derived class, the base class method gets executed. Using derived class&#8217;s object we can call base class&#8217;s methods, but the reverse is not allowed.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Unlike C++, C# does not support multiple inheritance. So, in C# every class has exactly one base class.<br />
Now, suppose we declare reference to the base class and store in it the address of instance of derived class as shown below.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">        account a1 = new    savingaccount ( &#8220;Amar&#8221;, 5600.00f ) ;<br />
   account a2 = new currentaccount ( &#8220;MyCompany Pvt. Ltd.&#8221;, 126000.00f) ;<br />
Such a situation arises when we have to decide at run-time a method of which class in a class hierarchy should get called. Using a1 and a2, suppose we call the method display( ), ideally the method of derived class should get called. But it is the method of base class that gets called. This is because the compiler considers the type of reference (account in this case) and resolves the method call. So, to call the proper method we must make a small change in our program. We must use the virtual keyword while defining the methods in base class as shown below.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">        public virtual void display( )    {   }<br />
We must declare the methods as virtual if they are going to be overridden in derived class. To override a virtual method in derived classes we must use the override keyword as given below.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">        public override void display( )   {   }<br />
Now it is ensured that when we call the methods using upcasted reference, it is the derived class&#8217;s method that would get called. Actually, when we declare a virtual method, while calling it, the compiler considers the contents of the reference rather than its type.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">If we don&#8217;t want to override base class&#8217;s virtual method, we can declare it with new modifier in derived class. The new modifier indicates that the method is new to this class and is not an override of a base class method.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How would you implement inheritance using VB.NET/C#?<br />
</strong>When we set out to implement a class using inheritance, we must first start with an existing class from which we will derive our new subclass. This existing class, or base class, may be part of the .NET system class library framework, it may be part of some other application or .NET assembly, or we may create it as part of our existing application. Once we have a base class, we can then implement one or more subclasses based on that base class. Each of our subclasses will automatically have all of the methods, properties, and events of that base class ? including the implementation behind each method, property, and event. Our subclass can add new methods, properties, and events of its own - extending the original interface with new functionality. Additionally, a subclass can replace the methods and properties of the base class with its own new<br />
implementation - effectively overriding the original behavior and replacing it with new behaviors. Essentially inheritance is a way of merging functionality from an existing class into our new subclass. Inheritance also defines rules for how these methods, properties, and events can be merged. In VB.NET we can use implements keyword for inheritance, while in C# we can use the sign ( :: ) between subclass and baseclass. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How is a property designated as read-only?<br />
</strong>In VB.NET:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Private mPropertyName as DataType<br />
Public ReadOnly Property PropertyName() As DataType<br />
    Get Return mPropertyName<br />
    End Get<br />
End Property</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">In C#</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Private DataType mPropertyName;<br />
public returntype PropertyName<br />
{<br />
      get{<br />
                        //property implementation goes here<br />
                        return mPropertyName;<br />
            }<br />
            // Do not write the set implementation<br />
}</font><br />
<font size="2" face="Geneva, Arial, Sans-serif"><strong>What is hiding in CSharp ?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Hiding is also called as Shadowing. This is the concept of Overriding the methods. It is a concept used in the Object Oriented Programming.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">E.g.<br />
 public class ClassA {<br />
 public virtual void MethodA() {<br />
  Trace.WriteLine(&#8221;ClassA Method&#8221;);<br />
 }<br />
}</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">public class ClassB : ClassA {<br />
 public new void MethodA() {<br />
  Trace.WriteLine(&#8221;SubClass ClassB Method&#8221;);<br />
 }<br />
}</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">public class TopLevel {<br />
 static void Main(string[] args) {<br />
  TextWriter tw = Console.Out;<br />
  Trace.Listeners.Add(new TextWriterTraceListener(tw));<br />
 <br />
  ClassA obj = new ClassB();<br />
  obj.MethodA(); // Outputs “Class A Method&#8221;<br />
 <br />
  ClassB obj1 = new ClassB();<br />
  obj.MethodA(); // Outputs “SubClass ClassB Method”<br />
 }<br />
}</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is the difference between an XML &#8220;Fragment&#8221; and an XML &#8220;Document.&#8221;<br />
</strong>An XML fragment is an XML document with no single top-level root element. To put it simple it is a part (fragment) of a well-formed xml document. (node) Where as a well-formed xml document must have only one root element. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What does it meant to say “the canonical” form of XML? </strong><br />
&#8220;The purpose of Canonical XML is to define a standard format for an XML document. Canonical XML is a very strict XML syntax, which lets documents in canonical XML be compared directly.<br />
Using this strict syntax makes it easier to see whether two XML documents are the same. For example, a section of text in one document might read Black &amp; White, whereas the same section of text might read Black &amp; White in another document, and even in another. If you compare those three documents byte by byte, they&#8217;ll be different. But if you write them all in canonical XML, which specifies every aspect of the syntax you can use, these three documents would all have the same version of this text (which would be Black &amp; White) and could be compared without problem.<br />
This Comparison is especially critical when xml documents are digitally signed. The digital signal may be interpreted in different way and the document may be rejected. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><br />
<font size="2" face="Geneva, Arial, Sans-serif"><strong>Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?<br />
</strong>&#8220;The XML Information Set (Infoset) defines a data model for XML. The Infoset describes the abstract representation of an XML Document. Infoset is the generalized representation of the XML Document, which is primarily meant to act as a set of definitions used by XML technologies to formally describe what parts of an XML document they operate upon.<br />
The Document Object Model (DOM) is one technology for representing an XML Document in memory and to programmatically read, modify and manipulate a xml document.<br />
Infoset helps defining generalized standards on how to use XML that is not dependent or tied to a particular XML specification or API. The Infoset tells us what part of XML Document should be considered as significant information. </font></p>
<p></font><font size="2" face="Geneva, Arial, Sans-serif"><strong>Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?<br />
</strong>Document Type Definition (DTD) describes a model or set of rules for an XML document. XML Schema Definition (XSD) also describes the structure of an XML document but XSDs are much more powerful.<br />
The disadvantage with the Document Type Definition is it doesn’t support data types beyond the basic 10 primitive types. It cannot properly define the type of data contained by the tag.<br />
An Xml Schema provides an Object Oriented approach to defining the format of an xml document. The Xml schema support most basic programming types like integer, byte, string, float etc., We can also define complex types of our own which can be used to define a xml document.<br />
Xml Schemas are always preferred over DTDs as a document can be more precisely defined using the XML Schemas because of its rich support for data representation. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Speaking of Boolean data types, what&#8217;s different between C# and C/C++?<br />
</strong>There&#8217;s no conversion between 0 and false, as well as any other number and true, like in C/C++. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How do you convert a string into an integer in .NET?</strong><br />
Int32.Parse(string) </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can you declare a C++ type destructor in C# like ~MyClass()?<br />
</strong>Yes, but what&#8217;s the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up,  plus, it introduces additional load on the garbage collector.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s different about namespace declaration when comparing that to package declaration in Java?<br />
</strong>No semicolon. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s the difference between const and readonly? </strong><br />
The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants as in the following example:<br />
public static readonly uint l1 = (uint) DateTime.Now.Ticks;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=55</wfw:commentRss>
		</item>
		<item>
		<title>C# Interview Questions 3</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=54</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=54#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:26:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[C# Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=54</guid>
		<description><![CDATA[What does \a character do?
On most systems, produces a rather annoying beep. 
Can you create enumerated data types in C#?
Yes. 
What&#8217;s different about switch statements in C#? 
No fall-throughs allowed. 
What happens when you encounter a continue statement inside the for loop?
The code for the rest of the loop is ignored, the control is transferred [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What does \a character do?<br />
</strong>On most systems, produces a rather annoying beep. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can you create enumerated data types in C#?<br />
</strong>Yes. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s different about switch statements in C#? </strong><br />
No fall-throughs allowed. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What happens when you encounter a continue statement inside the for loop?<br />
</strong>The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How can you sort the elements of the array in descending order? </strong><br />
By calling Sort() and then Reverse() methods. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Will finally block get executed if the exception had not occurred?<br />
</strong>Yes. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?<br />
</strong>A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can multiple catch blocks be executed?</strong><br />
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Why is it a bad idea to throw your own exceptions?<br />
</strong>Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s the difference between // comments, /* */ comments and /// comments?<br />
</strong>Single-line, multi-line and XML documentation comments. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How do you generate documentation from the C# file commented properly with a command-line compiler?<br />
</strong>Compile it with a /doc switch. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can you change the value of a variable while debugging a C# application? </strong><br />
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What&#8217;s the implicit name of the parameter that gets passed into the class&#8217; set method?<br />
</strong>Value, and it&#8217;s datatype depends on whatever variable we&#8217;re changing. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How do you inherit from a class in C#? </strong><br />
Place a colon and then the name of the base class. Notice that it&#8217;s double colon in C++. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Does C# support multiple inheritance?<br />
</strong>No, use interfaces instead. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>So how do you retrieve the customized properties of a .NET application from XML .config file? Can you automate this process?<br />
</strong>Initialize an instance of AppSettingsReader class. Call the GetValue method of AppSettingsReader class, passing in the name of the property and the type expected. Assign the result to the appropriate variable. In Visual Studio yes, use Dynamic Properties for automatic .config creation, storage and retrieval. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio?<br />
</strong>The designer will likely through it away, most of the code inside InitializeComponent is auto-generated. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Where do you add an event handler?</strong><br />
It&#8217;s the Attributesproperty, the Add function inside that property.<br />
e.g. btnSubmit.Attributes.Add(&#8221;"onMouseOver&#8221;",&#8221;"someClientCode();&#8221;")</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are jagged array?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">First lets us answer the question that what an array is?<br />
The dictionary meaning of array is an orderly arrangement or sequential arrangement of elements.<br />
In computer science term:<br />
An array is a data structure that contains a number of variables, which are accessed through computed indices. The variables contained in an array, also called the elements of the array, are all of the same type, and this type is called the element type of the array.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">An array has a rank that determines the number of indices associated with each array element. The rank of an array is also referred to as the dimensions of the array. An array with a rank of one is called a single-dimensional array. An array with a rank greater than one is called a multi-dimensional array. Specific sized multidimensional arrays are often referred to as two-dimensional arrays, three-dimensional arrays, and so on.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Now let us answer What are jagged arrays?<br />
</em> A jagged array is an array whose elements are arrays. The elements of jagged array can be of different dimensions and sizes. A jagged array is sometimes called as “array-of-arrays”. It is called jagged because each of its rows is of different size so the final or graphical representation is not a square.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"> When you create a jagged array you declare the number of rows in your array. Each row will hold an array that will be on any length. Before filling the values in the inner arrays you must declare them.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Jagged array declaration in C#:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"> For e.g. : int [] [] myJaggedArray = new int [3][];</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Declaration of inner arrays:<br />
 <br />
 myJaggedArray[0] = new int[5] ;   // First inner array will be of length 5.<br />
 myJaggedArray[1] = new int[4] ;  // Second inner array will be of length 4.<br />
 myJaggedArray[2] = new int[3] ;   // Third inner array will be of length 3.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Now to access third element of second row we write:<br />
  int value = myJaggedArray[1][2];</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Note that while declaring the array the second dimension is not supplied because this you will declare later on in the code.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Jagged array are created out of single dimensional arrays so be careful while using them. Don’t confuse it with multi-dimensional arrays because unlike them jagged arrays are not rectangular arrays.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">For more information on arrays:<br />
</font><a target="_top" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfarrayspg.asp"><font size="2" face="Geneva, Arial, Sans-serif">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfarrayspg.asp</font></a><font size="2" face="Geneva, Arial, Sans-serif"> </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is a delegate, why should you use it and how do you call it ?<br />
</strong>A delegate is a reference type that refers to a Shared method of a type or to an instance method of an object. Delegate is like a function pointer in C and C++.  Pointers are used to store the address of a thing. Delegate lets some other code call your function without needing to know where your function is actually located. All events in .NET actually use delegates in the background to wire up events. Events are really just a modified form of a delegate.<br />
It should give you an idea of some different areas in which delegates may be appropriate:</font><font size="2" face="Geneva, Arial, Sans-serif"></p>
<ul type="disc">
<li><span>They enable callback functionality in multi-tier applications as demonstrated in the examples above. &lt;o:p&gt;&lt;/o:p&gt;</span></li>
<li><span>The CacheItemRemoveCallback delegate can be used in ASP.NET to keep cached information up to date. When the cached information is removed for any reason, the associated callback is exercised and could contain a reload of the cached information. &lt;o:p&gt;&lt;/o:p&gt;</span></li>
<li><span>Use delegates to facilitate asynchronous processing for methods that do not offer asynchronous behavior. </span></li>
<li><span>Events use delegates so clients can give the application events to call when the event is fired. Exposing custom events within your applications requires the use of delegates.</span><span> </span></li>
</ul>
<p><span><font size="2"><font face="Geneva, Arial, Sans-serif"><strong>How does the XmlSerializer work? </strong><br />
XmlSerializer in the .NET Framework is a great tool to convert Xml into runtime objects and vice </font>versa</font></span></p>
<p><span><strong>If you define integer variable and a object variable and a structure then how those will be plotted in memory.</strong></span></p>
<p><span>Integer , structure – System.ValueType  &#8212; Allocated memory on stack , infact integer is primitive type recognized and allocated memory by compiler itself .</span></p>
<p><span>Infact , System.Int32 definition is as follows :</span></p>
<p><span>[C#]<br />
[Serializable]<br />
public struct Int32 : IComparable, IFormattable, IConvertible</span></p>
<p><span>So , it’s a struct by definition , which is the same case with various other value types .</span></p>
<p><span>Object – Base class , that is by default reference type , so at runtime JIT compiler allocates memory on the “Heap” Data structure . </span></p>
<p><span>Reference types are defined as class , derived directly or indirectly by System.ReferenceType </span></p>
<p></font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=54</wfw:commentRss>
		</item>
		<item>
		<title>ADO.Net Interview Questions 3</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=53</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=53#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:24:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ADO.Net Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=53</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p><strong><font size="2" face="Arial">How do you handle data concurrency in .NET ?</font></strong><font size="2" face="Arial">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.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">In this column, I&#8217;ll explore how ADO.NET is equipped to detect and handle concurrency violations. I&#8217;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.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><br />
<em>Is Your Glass Half Full?</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">There are three common techniques for managing what happens when users try to modify the same data at the same time: pessimistic, optimistic, and last-in wins. They each handle concurrency issues differently.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The pessimistic approach says: &#8220;Nobody can cause a concurrency violation with my data if I do not let them get at the data while I have it.&#8221; This tactic prevents concurrency in the first place but it limits scalability because it prevents all concurrent access. Pessimistic concurrency generally locks a row from the time it is retrieved until the time updates are flushed to the database. Since this requires a connection to remain open during the entire process, pessimistic concurrency cannot successfully be implemented in a disconnected model like the ADO.NET DataSet, which opens a connection only long enough to populate the DataSet then releases and closes, so a database lock cannot be held.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Another technique for dealing with concurrency is the last-in wins approach. This model is pretty straightforward and easy to implement-whatever data modification was made last is what gets written to the database. To implement this technique you only need to put the primary key fields of the row in the UPDATE statement&#8217;s WHERE clause. No matter what is changed, the UPDATE statement will overwrite the changes with its own changes since all it is looking for is the row that matches the primary key values. Unlike the pessimistic model, the last-in wins approach allows users to read the data while it is being edited on screen. However, problems can occur when users try to modify the same data at the same time because users can overwrite each other&#8217;s changes without being notified of the collision. The last-in wins approach does not detect or notify the user of violations because it does not care. However the optimistic technique does detect violations. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">In optimistic concurrency models, a row is only locked during the update to the database. Therefore the data can be retrieved and updated by other users at any time other than during the actual row update operation. Optimistic concurrency allows the data to be read simultaneously by multiple users and blocks other users less often than its pessimistic counterpart, making it a good choice for ADO.NET. In optimistic models, it is important to implement some type of concurrency violation detection that will catch any additional attempt to modify records that have already been modified but not committed. You can write your code to handle the violation by always rejecting and canceling the change request or by overwriting the request based on some business rules. Another way to handle the concurrency violation is to let the user decide what to do. The sample application that is shown in Figure 1 illustrates some of the options that can be presented to the user in the event of a concurrency violation.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Where Did My Changes Go?</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">When users are likely to overwrite each other&#8217;s changes, control mechanisms should be put in place. Otherwise, changes could be lost. If the technique you&#8217;re using is the last-in wins approach, then these types of overwrites are entirely possible.For example, imagine Julie wants to edit an employee&#8217;s last name to correct the spelling. She navigates to a screen which loads the employee&#8217;s information into a DataSet and has it presented to her in a Web page. Meanwhile, Scott is notified that the same employee&#8217;s phone extension has changed. While Julie is correcting the employee&#8217;s last name, Scott begins to correct his extension. Julie saves her changes first and then Scott saves his.Assuming that the application uses the last-in wins approach and updates the row using a SQL WHERE clause containing only the primary key&#8217;s value, and assuming a change to one column requires the entire row to be updated, neither Julie nor Scott may immediatelyrealize the concurrency issue that just occurred. In this particular situation, Julie&#8217;s changes were overwritten by Scott&#8217;s changes because he saved last, and the last name reverted to the misspelled version.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">So as you can see, even though the users changed different fields, their changes collided and caused Julie&#8217;s changes to be lost. Without some sort of concurrency detection and handling, these types of overwrites can occur and even go unnoticed.When you run the sample application included in this column&#8217;s download, you should open two separate instances of Microsoft® Internet Explorer. When I generated the conflict, I opened two instances to simulate two users with two separate sessions so that a concurrency violation would occur in the sample application. When you do this, be careful not to use Ctrl+N because if you open one instance and then use the Ctrl+N technique to open another instance, both windows will share the same session.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Detecting Violations</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The concurrency violation reported to the user in Figure 1 demonstrates what can happen when multiple users edit the same data at the same time. In Figure 1, the user attempted to modify the first name to &#8220;Joe&#8221; but since someone else had already modified the last name to &#8220;Fuller III,&#8221; a concurrency violation was detected and reported. ADO.NET detects a concurrency violation when a DataSet containing changed values is passed to a SqlDataAdapter&#8217;s Update method and no rows are actually modified. Simply using the primary key (in this case the EmployeeID) in the UPDATE statement&#8217;s WHERE clause will not cause a violation to be detected because it still updates the row (in fact, this technique has the same outcome as the last-in wins technique). Instead, more conditions must be specified in the WHERE clause in order for ADO.NET to detect the violation.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The key here is to make the WHERE clause explicit enough so that it not only checks the primary key but that it also checks for another appropriate condition. One way to accomplish this is to pass in all modifiable fields to the WHERE clause in addition to the primary key. For example, the application shown in Figure 1 could have its UPDATE statement look like the stored procedure that&#8217;s shown in Figure 2.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Notice that in the code in Figure 2 nullable columns are also checked to see if the value passed in is NULL. This technique is not only messy but it can be difficult to maintain by hand and it requires you to test for a significant number of WHERE conditions just to update a row. This yields the desired result of only updating rows where none of the values have changed since the last time the user got the data, but there are other techniques that do not require such a huge WHERE clause.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Another way to make sure that the row is only updated if it has not been modified by another user since you got the data is to add a timestamp column to the table. The SQL Server(tm) TIMESTAMP datatype automatically updates itself with a new value every time a value in its row is modified. This makes it a very simple and convenient tool to help detect concurrency violations.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">A third technique is to use a DATETIME column in which to track changes to its row. In my sample application I added a column called LastUpdateDateTime to the Employees table. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">ALTER TABLE Employees ADD LastUpdateDateTime DATETIME</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">There I update the value of the LastUpdateDateTime field automatically in the UPDATE stored procedure using the built-in SQL Server GETDATE function. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The binary TIMESTAMP column is simple to create and use since it automatically regenerates its value each time its row is modified, but since the DATETIME column technique is easier to display on screen and demonstrate when the change was made, I chose it for my sample application. Both of these are solid choices, but I prefer the TIMESTAMP technique since it does not involve any additional code to update its value.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Retrieving Row Flags</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">One of the keys to implementing concurrency controls is to update the timestamp or datetime field&#8217;s value back into the DataSet. If the same user wants to make more modifications, this updated value is reflected in the DataSet so it can be used again. There are a few different ways to do this. The fastest is using output parameters within the stored procedure. (This should only return if @@ROWCOUNT equals 1.) The next fastest involves selecting the row again after the UPDATE within the stored procedure. The slowest involves selecting the row from another SQL statement or stored procedure from the SqlDataAdapter&#8217;s RowUpdated event.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">I prefer to use the output parameter technique since it is the fastest and incurs the least overhead. Using the RowUpdated event works well, but it requires me to make a second call from the application to the database. The following code snippet adds an output parameter to the SqlCommand object that is used to update the Employee information: </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">oUpdCmd.Parameters.Add(new SqlParameter(&#8221;@NewLastUpdateDateTime&#8221;, </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">  SqlDbType.DateTime, 8, ParameterDirection.Output, </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">  false, 0, 0, &#8220;LastUpdateDateTime&#8221;, DataRowVersion.Current, null));</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">oUpdCmd.UpdatedRowSource = UpdateRowSource.OutputParameters;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The output parameter has its sourcecolumn and sourceversion arguments set to point the output parameter&#8217;s return value back to the current value of the LastUpdateDateTime column of the DataSet. This way the updated DATETIME value is retrieved and can be returned to the user&#8217;s .aspx page.</font></p>
<p><em><font size="2" face="Arial">Saving Changes</font></em></p>
<p><font size="2" face="Arial">Now that the Employees table has the tracking field (LastUpdateDateTime) and the stored procedure has been created to use both the primary key and the tracking field in the WHERE clause of the UPDATE statement, let&#8217;s take a look at the role of ADO.NET. In order to trap the event when the user changes the values in the textboxes, I created an event handler for the TextChanged event for each TextBox control: </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">private void txtLastName_TextChanged(object sender, System.EventArgs e)</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">{</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    // Get the employee DataRow (there is only 1 row, otherwise I could</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    // do a Find)</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    dsEmployee.EmployeeRow oEmpRow =</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">           (dsEmployee.EmployeeRow)oDsEmployee.Employee.Rows[0];</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    oEmpRow.LastName = txtLastName.Text;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    // Save changes back to Session</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">    Session[&#8221;oDsEmployee&#8221;] = oDsEmployee;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">}</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">This event retrieves the row and sets the appropriate field&#8217;s value from the TextBox. (Another way of getting the changed values is to grab them when the user clicks the Save button.) Each TextChanged event executes after the Page_Load event fires on a postback, so assuming the user changed the first and last names, when the user clicks the Save button, the events could fire in this order: Page_Load, txtFirstName_TextChanged, txtLastName_TextChanged, and btnSave_Click.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The Page_Load event grabs the row from the DataSet in the Session object; the TextChanged events update the DataRow with the new values; and the btnSave_Click event attempts to save the record to the database. The btnSave_Click event calls the SaveEmployee method (shown in Figure 3) and passes it a bLastInWins value of false since we want to attempt a standard save first. If the SaveEmployee method detects that changes were made to the row (using the HasChanges method on the DataSet, or alternatively using the RowState property on the row), it creates an instance of the Employee class and passes the DataSet to its SaveEmployee method. The Employee class could live in a logical or physical middle tier. (I wanted to make this a separate class so it would be easy to pull the code out and separate it from the presentation logic.) </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Notice that I did not use the GetChanges method to pull out only the modified rows and pass them to the Employee object&#8217;s Save method. I skipped this step here since there is only one row. However, if there were multiple rows in the DataSet&#8217;s DataTable, it would be better to use the GetChanges method to create a DataSet that contains only the modified rows.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">If the save succeeds, the Employee.SaveEmployee method returns a DataSet containing the modified row and its newly updated row version flag (in this case, the LastUpdateDateTime field&#8217;s value). This DataSet is then merged into the original DataSet so that the LastUpdateDateTime field&#8217;s value can be updated in the original DataSet. This must be done because if the user wants to make more changes she will need the current values from the database merged back into the local DataSet and shown on screen. This includes the LastUpdateDateTime value which is used in the WHERE clause. Without this field&#8217;s current value, a false concurrency violation would occur.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Reporting Violations</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">If a concurrency violation occurs, it will bubble up and be caught by the exception handler shown in Figure 3 in the catch block for DBConcurrencyException. This block calls the FillConcurrencyValues method, which displays both the original values in the DataSet that were attempted to be saved to the database and the values currently in the database. This method is used merely to show the user why the violation occurred. Notice that the exDBC variable is passed to the FillConcurrencyValues method. This instance of the special database concurrency exception class (DBConcurrencyException) contains the row where the violation occurred. When a concurrency violation occurs, the screen is updated to look like Figure 1.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The DataSet not only stores the schema and the current data, it also tracks changes that have been made to its data. It knows which rows and columns have been modified and it keeps track of the before and after versions of these values. When accessing a column&#8217;s value via the DataRow&#8217;s indexer, in addition to the column index you can also specify a value using the DataRowVersion enumerator. For example, after a user changes the value of the last name of an employee, the following lines of C# code will retrieve the original and current values stored in the LastName column: </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">string sLastName_Before = oEmpRow[&#8221;LastName&#8221;, DataRowVersion.Original];</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">string sLastName_After = oEmpRow[&#8221;LastName&#8221;, DataRowVersion.Current];</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The FillConcurrencyValues method uses the row from the DBConcurrencyException and gets a fresh copy of the same row from the database. It then displays the values using the DataRowVersion enumerators to show the original value of the row before the update and the value in the database alongside the current values in the textboxes.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>User&#8217;s Choice</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Once the user has been notified of the concurrency issue, you could leave it up to her to decide how to handle it. Another alternative is to code a specific way to deal with concurrency, such as always handling the exception to let the user know (but refreshing the data from the database). In this sample application I let the user decide what to do next. She can either cancel changes, cancel and reload from the database, save changes, or save anyway.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The option to cancel changes simply calls the RejectChanges method of the DataSet and rebinds the DataSet to the controls in the ASP.NET page. The RejectChanges method reverts the changes that the user made back to its original state by setting all of the current field values to the original field values. The option to cancel changes and reload the data from the database also rejects the changes but additionally goes back to the database via the Employee class in order to get a fresh copy of the data before rebinding to the control on the ASP.NET page.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The option to save changes attempts to save the changes but will fail if a concurrency violation is encountered. Finally, I included a &#8220;save anyway&#8221; option. This option takes the values the user attempted to save and uses the last-in wins technique, overwriting whatever is in the database. It does this by calling a different command object associated with a stored procedure that only uses the primary key field (EmployeeID) in the WHERE clause of the UPDATE statement. This technique should be used with caution as it will overwrite the record.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">If you want a more automatic way of dealing with the changes, you could get a fresh copy from the database. Then overwrite just the fields that the current user modified, such as the Extension field. That way, in the example I used the proper LastName would not be overwritten. Use this with caution as well, however, because if the same field was modified by both users, you may want to just back out or ask the user what to do next. What is obvious here is that there are several ways to deal with concurrency violations, each of which must be carefully weighed before you decide on the one you will use in your application.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><em>Wrapping It Up</em></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Setting the SqlDataAdapter&#8217;s ContinueUpdateOnError property tells the SqlDataAdapter to either throw an exception when a concurrency violation occurs or to skip the row that caused the violation and to continue with the remaining updates. By setting this property to false (its default value), it will throw an exception when it encounters a concurrency violation. This technique is ideal when only saving a single row or when you are attempting to save multiple rows and want them all to commit or all to fail.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">I have split the topic of concurrency violation management into two parts. Next time I will focus on what to do when multiple rows could cause concurrency violations. I will also discuss how the DataViewRowState enumerators can be used to show what changes have been made to a DataSet.</font></p>
<p><font face="Geneva, Arial, Sans-serif"><font size="2"><strong>How you will set the datarelation between two columns?<br />
</strong>ADO.NET provides DataRelation object to set relation between two columns.It helps to enforce the following  constraints,a unique constraint, which guarantees that a column in the table  contains no duplicates and a foreign-key constraint,which can be used to maintain referential  integrity.A unique constraint is implemented either by simply setting the Unique property of a data  column to true, or by adding an instance of the UniqueConstraint class to the DataRelation object&#8217;s ParentKeyConstraint. As part of the foreign-key constraint, you can specify referential integrity  rules that are applied at three points,when a parent record is updated,when a parent record is deleted and when a change is accepted or rejected</font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=53</wfw:commentRss>
		</item>
		<item>
		<title>ADO.Net Interview Questions 2</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=52</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=52#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:23:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ADO.Net Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=52</guid>
		<description><![CDATA[Explain what a diffgram is and its usage ?
A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Explain what a diffgram is and its usage ?</strong><br />
A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used. Additionally, when loading the contents of a DataSet from XML using the ReadXml method, or when writing the contents of a DataSet in XML using the WriteXml method, you can select that the contents be read or written as a DiffGram. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The DiffGram format is divided into three sections: the current data, the original (or &#8220;before&#8221;) data, and an errors section, as shown in the following example.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">&lt;?xml version=&#8221;1.0&#8243;?&gt;<br />
&lt;diffgr:diffgram<br />
         xmlns:msdata=&#8221;urn:schemas-microsoft-com:xml-msdata&#8221;<br />
         xmlns:diffgr=&#8221;urn:schemas-microsoft-com:xml-diffgram-v1&#8243;<br />
         xmlns:xsd=&#8221;</font><a target="_top" href="http://www.w3.org/2001/XMLSchema"><font size="2" face="Geneva, Arial, Sans-serif">http://www.w3.org/2001/XMLSchema</font></a><font size="2" face="Geneva, Arial, Sans-serif">&#8220;&gt;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">   &lt;DataInstance&gt;<br />
   &lt;/DataInstance&gt;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">  &lt;diffgr:before&gt;<br />
  &lt;/diffgr:before&gt;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">  &lt;diffgr:errors&gt;<br />
  &lt;/diffgr:errors&gt;<br />
&lt;/diffgr:diffgram&gt;</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The DiffGram format consists of the following blocks of data: </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">&lt;DataInstance&gt;<br />
The name of this element, DataInstance, is used for explanation purposes in this documentation. A DataInstance element represents a DataSet or a row of a DataTable. Instead of DataInstance, the element would contain the name of the DataSet or DataTable. This block of the DiffGram format contains the current data, whether it has been modified or not. An element, or row, that has been modified is identified with the diffgr:hasChanges annotation.<br />
&lt;diffgr:before&gt;<br />
This block of the DiffGram format contains the original version of a row. Elements in this block are matched to elements in the DataInstance block using the diffgr:id annotation.<br />
&lt;diffgr:errors&gt;<br />
This block of the DiffGram format contains error information for a particular row in the DataInstance block. Elements in this block are matched to elements in the DataInstance block using the diffgr:id annotation.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Which method do you invoke on the DataAdapter control to load your generated dataset with data?<br />
You have to use the Fill method of the DataAdapter control and pass the dataset object as an argument to load the generated data.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Can you edit data in the Repeater control?<br />
</strong>NO.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Which are the different IsolationLevels ?</strong><br />
Following are the various IsolationLevels:</font></p>
<ul>
<li><font size="2" face="Geneva, Arial, Sans-serif">Serialized   Data read by a current transaction cannot be changed by another transaction until the current transaction finishes. No new data can be inserted that would affect the current transaction. This is the safest isolation level and is the default. </font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">Repeatable Read   Data read by a current transaction cannot be changed by another transaction until the current transaction finishes. Any type of new data can be inserted during a transaction. </font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">Read Committed   A transaction cannot read data that is being modified by another transaction that has not committed. This is the default isolation level in Microsoft® SQL Server. </font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">Read Uncommitted   A transaction can read any data, even if it is being modified by another transaction. This is the least safe isolation level but allows the highest concurrency. </font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">Any   Any isolation level is supported. This setting is most commonly used by downstream components to avoid conflicts. This setting is useful because any downstream component must be configured with an isolation level that is equal to or less than the isolation level of its immediate upstream component. Therefore, a downstream component that has its isolation level configured as Any always uses the same isolation level that its immediate upstream component uses. If the root object in a transaction has its isolation level configured to Any, its isolation level becomes Serialized. </font></li>
</ul>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How xml files and be read and write using dataset?.<br />
</strong>DataSet exposes method like ReadXml and WriteXml to read and write xml</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are the different rowversions available?</strong><br />
There are four types of Rowversions.<br />
Current:<br />
The current values for the row. This row version does not exist for rows with a RowState of Deleted.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Default :<br />
The row the default version for the current DataRowState. For a DataRowState value of Added, Modified or Current, the default version is Current. For a DataRowState of Deleted, the version is Original. For a DataRowState value of Detached, the version is Proposed.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Original:<br />
The row contains its original values.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Proposed:<br />
The proposed values for the row. This row version exists during an edit operation on a row, or for a row that is not part of a DataRowCollection</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Explain acid properties?.<br />
</strong>The term ACID conveys the role transactions play in mission-critical applications. Coined by transaction processing pioneers, ACID stands for atomicity, consistency, isolation, and durability.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">These properties ensure predictable behavior, reinforcing the role of transactions as all-or-none propositions designed to reduce the management load when there are many variables.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Atomicity<br />
A transaction is a unit of work in which a series of operations occur between the BEGIN TRANSACTION and END TRANSACTION statements of an application. A transaction executes exactly once and is atomic — all the work is done or none of it is.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Operations associated with a transaction usually share a common intent and are interdependent. By performing only a subset of these operations, the system could compromise the overall intent of the transaction. Atomicity eliminates the chance of processing a subset of operations.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Consistency<br />
A transaction is a unit of integrity because it preserves the consistency of data, transforming one consistent state of data into another consistent state of data.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Consistency requires that data bound by a transaction be semantically preserved. Some of the responsibility for maintaining consistency falls to the application developer who must make sure that all known integrity constraints are enforced by the application. For example, in developing an application that transfers money, you should avoid arbitrarily moving decimal points during the transfer.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Isolation<br />
A transaction is a unit of isolation — allowing concurrent transactions to behave as though each were the only transaction running in the system.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Isolation requires that each transaction appear to be the only transaction manipulating the data store, even though other transactions may be running at the same time. A transaction should never see the intermediate stages of another transaction.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Transactions attain the highest level of isolation when they are serializable. At this level, the results obtained from a set of concurrent transactions are identical to the results obtained by running each transaction serially. Because a high degree of isolation can limit the number of concurrent transactions, some applications reduce the isolation level in exchange for better throughput.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Durability<br />
A transaction is also a unit of recovery. If a transaction succeeds, the system guarantees that its updates will persist, even if the computer crashes immediately after the commit. Specialized logging allows the system&#8217;s restart procedure to complete unfinished operations, making the transaction durable.</font><br />
<font size="2" face="Geneva, Arial, Sans-serif"><strong>Whate are different types of Commands available with DataAdapter ?<br />
</strong>The SqlDataAdapter has SelectCommand, InsertCommand, DeleteCommand and UpdateCommand</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is a Dataset?</strong><br />
Datasets are the result of bringing together ADO and XML. A dataset contains one or more data of tabular XML, known as DataTables, these data can be treated separately, or can have relationships defined between them. Indeed these relationships give you ADO data SHAPING without needing to master the SHAPE language, which many people are not comfortable with.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The dataset is a disconnected in-memory cache database. The dataset object model looks like this:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Dataset<br />
  DataTableCollection<br />
  DataTable<br />
   DataView<br />
   DataRowCollection<br />
    DataRow<br />
   DataColumnCollection<br />
    DataColumn<br />
   ChildRelations<br />
   ParentRelations<br />
   Constraints<br />
   PrimaryKey<br />
DataRelationCollection</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Let’s take a look at each of these:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataTableCollection: As we say that a DataSet is an in-memory database. So it has this collection, which holds data from multiple tables in a single DataSet object.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataTable: In the DataTableCollection, we have DataTable objects, which represents the individual tables of the dataset. </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataView: The way we have views in database, same way we can have DataViews. We can use these DataViews to do Sort, filter data.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataRowCollection: Similar to DataTableCollection, to represent each row in each Table we have DataRowCollection.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataRow:  To represent each and every row of the DataRowCollection, we have DataRows.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataColumnCollection: Similar to DataTableCollection, to represent each column in each Table we have DataColumnCollection.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataColumn: To represent each and every Column of the DataColumnCollection, we have DataColumn.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">PrimaryKey: Dataset defines Primary key for the table and the primary key validation will take place without going to the database.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Constraints: We can define various constraints on the Tables, and can use Dataset.Tables(0).enforceConstraints. This will execute all the constraints, whenever we enter data in DataTable.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">DataRelationCollection: as we know that we can have more than 1 table in the dataset, we can also define relationship between these tables using this collection and maintain a parent-child relationship.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Explain the ADO . Net Architecture ( .Net Data Provider)<br />
</strong>ADO.Net is the data access model for .Net –based applications. It can be used to access relational database systems such as SQL SERVER 2000, Oracle, and many other data sources for which there is an OLD DB or ODBC provider. To a certain extent, ADO.NET represents the latest evolution of ADO technology. However, ADO.NET introduces some major changes and innovations that are aimed at the loosely coupled and inherently disconnected – nature of web applications.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">A .Net Framework data provider is used to connecting to a database, executing commands, and retrieving results. Those results are either processed directly, or placed in an ADO.NET DataSet in order to be exposed to the user in an ad-hoc manner, combined with data from multiple sources, or remoted between tiers. The .NET Framework data provider is designed to be lightweight, creating a minimal layer between the data source and your code, increasing performance without sacrificing functionality.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Following are the 4 core objects of .Net Framework Data provider:</font></p>
<ul>
<li><font size="2" face="Geneva, Arial, Sans-serif">Connection: Establishes a connection to a specific data source</font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">Command: Executes a command against a data source. Exposes Parameters and can execute within the scope of a Transaction from a Connection.</font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">DataReader: Reads a forward-only, read-only stream of data from a data source.</font></li>
<li><font size="2" face="Geneva, Arial, Sans-serif">DataAdapter: Populates a DataSet and resolves updates with the data source.</font></li>
</ul>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework includes the .NET Framework Data Provider for SQL Server (for Microsoft SQL Server version 7.0 or later), the .NET Framework Data Provider for OLE DB, and the .NET Framework Data Provider for ODBC.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework Data Provider for SQL Server:  The .NET Framework Data Provider for SQL Server uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer. The following illustration contrasts the .NET Framework Data Provider for SQL Server with the .NET Framework Data Provider for OLE DB. The .NET Framework Data Provider for OLE DB communicates to an OLE DB data source through both the OLE DB Service component, which provides connection pooling and transaction services, and the OLE DB Provider for the data source </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework Data Provider for OLE DB: The .NET Framework Data Provider for OLE DB uses native OLE DB through COM interoperability to enable data access. The .NET Framework Data Provider for OLE DB supports both local and distributed transactions. For distributed transactions, the .NET Framework Data Provider for OLE DB, by default, automatically enlists in a transaction and obtains transaction details from Windows 2000 Component Services.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework Data Provider for ODBC: The .NET Framework Data Provider for ODBC uses native ODBC Driver Manager (DM) through COM interoperability to enable data access. The ODBC data provider supports both local and distributed transactions. For distributed transactions, the ODBC data provider, by default, automatically enlists in a transaction and obtains transaction details from Windows 2000 Component Services.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework Data Provider for Oracle: The .NET Framework Data Provider for Oracle enables data access to Oracle data sources through Oracle client connectivity software. The data provider supports Oracle client software version 8.1.7 and later. The data provider supports both local and distributed transactions (the data provider automatically enlists in existing distributed transactions, but does not currently support the EnlistDistributedTransaction method).</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">The .NET Framework Data Provider for Oracle requires that Oracle client software (version 8.1.7 or later) be installed on the system before you can use it to connect to an Oracle data source.<br />
.NET Framework Data Provider for Oracle classes are located in the System.Data.OracleClient namespace and are contained in the System.Data.OracleClient.dll assembly. You will need to reference both the System.Data.dll and the System.Data.OracleClient.dll when compiling an application that uses the data provider.<br />
Choosing a .NET Framework Data Provider</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">.NET Framework Data Provider for SQL Server: Recommended for middle-tier applications using Microsoft SQL Server 7.0 or later. Recommended for single-tier applications using Microsoft Data Engine (MSDE) or Microsoft SQL Server 7.0 or later.<br />
Recommended over use of the OLE DB Provider for SQL Server (SQLOLEDB) with the .NET Framework Data Provider for OLE DB. For Microsoft SQL Server version 6.5 and earlier, you must use the OLE DB Provider for SQL Server with the .NET Framework Data Provider for OLE DB.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">.NET Framework Data Provider for OLE DB: Recommended for middle-tier applications using Microsoft SQL Server 6.5 or earlier, or any OLE DB provider. For Microsoft SQL Server 7.0 or later, the .NET Framework Data Provider for SQL Server is recommended. Recommended for single-tier applications using Microsoft Access databases. Use of a Microsoft Access database for a middle-tier application is not recommended.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">.NET Framework Data Provider for ODBC: Recommended for middle-tier applications using ODBC data sources. Recommended for single-tier applications using ODBC data sources.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">.NET Framework Data Provider for Oracle: Recommended for middle-tier applications using Oracle data sources. Recommended for single-tier applications using Oracle data sources. Supports Oracle client software version 8.1.7 and later. The .NET Framework Data Provider for Oracle classes are located in the System.Data.OracleClient namespace and are contained in the System.Data.OracleClient.dll assembly. You need to reference both the System.Data.dll and the System.Data.OracleClient.dll when compiling an application that uses the data provider.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?<br />
Let’s take a look at the differences between ADO Recordset and ADO.Net DataSet:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">1. Table Collection: ADO Recordset provides the ability to navigate through a single table of information. That table would have been formed with a join of multiple tables and returning columns from multiple tables. ADO.NET DataSet is capable of holding instances of multiple tables. It has got a Table Collection, which holds multiple tables in it. If the tables are having a relation, then it can be manipulated on a Parent-Child relationship. It has the ability to support multiple tables with keys, constraints and interconnected relationships. With this ability the DataSet can be considered as a small, in-memory relational database cache.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">2. Navigation: Navigation in ADO Recordset is based on the cursor mode. Even though it is specified to be a client-side Recordset, still the navigation pointer will move from one location to another on cursor model only. ADO.NET DataSet is an entirely offline, in-memory, and cache of data. All of its data is available all the time. At any time, we can retrieve any row or column, constraints or relation simply by accessing it either ordinarily or by retrieving it from a name-based collection.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">3. Connectivity Model: The ADO Recordset was originally designed without the ability to operate in a disconnected environment. ADO.NET DataSet is specifically designed to be a disconnected in-memory database. ADO.NET DataSet follows a pure disconnected connectivity model and this gives it much more scalability and versatility in the amount of things it can do and how easily it can do that.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">4. Marshalling and Serialization: In COM, through Marshalling, we can pass data from 1 COM component to another component at any time. Marshalling involves copying and processing data so that a complex type can appear to the receiving component the same as it appeared to the sending component. Marshalling is an expensive operation. ADO.NET Dataset and DataTable components support Remoting in the form of XML serialization. Rather than doing expensive Marshalling, it uses XML and sent data across boundaries.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">5. Firewalls and DCOM and Remoting: Those who have worked with DCOM know that how difficult it is to marshal a DCOM component across a router. People generally came up with workarounds to solve this issue. ADO.NET DataSet uses Remoting, through which a DataSet / DataTable component can be serialized into XML, sent across the wire to a new AppDomain, and then Desterilized back to a fully functional DataSet. As the DataSet is completely disconnected, and it has no dependency, we lose absolutely nothing by serializing and transferring it through Remoting.</font><br />
 </p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=52</wfw:commentRss>
		</item>
		<item>
		<title>COM and COM+ Interview Questions 1</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=51</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=51#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:19:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[COM and COM+ Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=51</guid>
		<description><![CDATA[What are different transaction options available for services components ?
There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types.
Disabled: - There is no transaction. COM+ does not provide transaction support for this component.
Not Supported: - Component does [...]]]></description>
			<content:encoded><![CDATA[<p><font face="Geneva, Arial, Sans-serif"><font size="2"><strong>What are different transaction options available for services components ?<br />
</strong>There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types.</font></font></p>
<p><font face="Geneva, Arial, Sans-serif"><font size="2"><strong>Disabled</strong>: - There is no transaction. COM+ does not provide transaction support for this component.</font></font></p>
<p><font face="Geneva, Arial, Sans-serif"><font size="2"><strong>Not Supported:</strong> - Component does not support transactions. Hence even if the calling component in the hierarchy is transaction enabled this component will not participate in the transaction.</font></font></p>
<p><font face="Geneva, Arial, Sans-serif"><font size="2"><strong>Supported</strong>: - Components with transaction type supported will be a part of the transaction if the calling component has an active transaction.<br />
If the calling component is not transaction enabled this component will not start a new transaction.</font></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Required</strong>: - Components with this attribute require a transaction i.e. either the calling should have a transaction in place else this component will start a new transaction.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Required</strong> <strong>New</strong>: - Components enabled with this transaction type always require a new transaction. Components with required new transaction type instantiate a new transaction for themselves every time.</font><br />
<font size="2" face="Geneva, Arial, Sans-serif"><strong>Can we use com Components in .net?.How ?.can we use .net components in vb?.Explain how ?</strong><br />
COM components have different internal architecture from .NET components hence they are not innately compatible. However .NET  framework supports invocation of unmanaged code from managed code (and vice-versa) through COM/.NET interoperability. .NET application communicates with a COM component through a managed wrapper of the component called Runtime Callable Wrapper (RCW); it acts as managed proxy to the unmanaged COM component. When a method call is made to COM object, it goes onto RCW and not the object itself. RCW manages the lifetime management of the COM component. Implementation Steps -</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Create Runtime Callable Wrapper out of COM component. Reference the metadata assembly Dll in the project and use its methods &amp; properties RCW can be created using Type Library Importer utility or through VS.NET. Using VS.NET, add reference through COM tab to select the desired DLL. VS.NET automatically generates metadata assembly putting the classes provided by that component into a namespace with the same name as COM dll (XYZRCW.dll)</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">.NET components can be invoked by unmanaged code through COM Callable Wrapper (CCW) in COM/.NET interop. The unmanaged code will talk to this proxy, which translates call to managed environment. We can use COM components in .NET through COM/.NET interoperability. When managed code calls an unmanaged component, behind the scene, .NET creates proxy called COM Callable wrapper (CCW), which accepts commands from a COM client, and forwards it to .NET component. There are two prerequisites to creating .NET component, to be used in unmanaged code:<br />
1. .NET class should be implement its functionality through interface. First define interface in code, then have the class to imlpement it. This way, it prevents breaking of COM client, if/when .NET component changes.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">2.Secondly, .NET class, which is to be visible to COM clients must be declared public. The tools that create the CCW only define types based<br />
on public classes. The same rule applies to methods, properties, and events that will be used by COM clients.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Implementation Steps -<br />
1. Generate type library of .NET component, using TLBExporter utility. A type library is the COM equivalent of the metadata contained within<br />
a .NET assembly. Type libraries are generally contained in files with the extension .tlb. A type library contains the necessary information to allow a COM client to determine which classes are located in a particular server, as well as the methods, properties, and events supported by those classes.<br />
2. Secondly,  use Assembly Registration tool (regasm) to create the type library and register it.<br />
3. Lastly install .NET assembly in GAC, so it is available as shared assembly.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is Runtime Callable wrapper?.when it will created?.</strong><br />
The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to .NET clients, its primary function is to marshal calls between a .NET client and a COM object. This wrapper turns the COM interfaces exposed by the COM component into .NET-compatible interfaces. For oleautomation (attribute indicates that an interface is compatible with Automation) interfaces, the RCW can be generated automatically from a type library. For non-oleautomation interfaces, it may be necessary to develop a custom RCW which manually maps the types exposed by the COM interface to .NET-compatible types.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is Com Callable wrapper?when it will created?<br />
</strong>.NET components are accessed from COM via a COM Callable Wrapper (CCW). This is similar to a RCW, but works in the opposite direction. Again, if the wrapper cannot be automatically generated by the .NET development tools, or if the automatic behaviour is not desirable, a custom CCW can be developed. Also, for COM to &#8217;see&#8217; the .NET component, the .NET component must be registered in the registry.CCWs also manage the object identity and object lifetime of the managed objects they wrap.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is a primary interop ?</strong><br />
A primary interop assembly is a collection of types that are deployed, versioned, and configured as a single unit. However, unlike other managed assemblies, an interop assembly contains type definitions (not implementation) of types that have already been defined in COM. These type definitions allow managed applications to bind to the COM types at compile time and provide information to the common language runtime<br />
about how the types should be marshaled at run time.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are tlbimp and tlbexp tools used for ?<br />
</strong>The Type Library Exporter generates a type library that describes the types defined in a common language runtime assembly.<br />
The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What benefit do you get from using a Primary Interop Assembly (PIA)?<br />
</strong>PIAs are important because they provide unique type identity. The PIA distinguishes the official type definitions from counterfeit definitions provided by other interop assemblies. Having a single type identity ensures type compatibility between applications that share the types defined in the PIA. Because the PIA is signed by its  publisher and labeled with the PrimaryInteropAssembly attribute, it can be differentiated from other interop assemblies that define the same types.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=51</wfw:commentRss>
		</item>
		<item>
		<title>Web Services Interview Questions 1</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=50</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=50#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:16:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Web Service Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=50</guid>
		<description><![CDATA[Can you give an example of when it would be appropriate to use a web service as opposed to non-serviced .NET component
Web service is one of main component in Service Oriented Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#990000"><font color="#990000">Can you give an example of when it would be appropriate to use a web service as opposed to non-serviced .NET component</font><br />
</font></strong>Web service is one of main component in Service Oriented Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented Architecture applications.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">What is the standard you use to wrap up a call to a Web service<br />
&#8220;SOAP.<br />
&#8220;</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660000">What is the transport protocol you use to call a Web service SOAP</font></strong><br />
HTTP with SOAP</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><font color="#660000"><strong>What does WSDL stand for?<br />
</strong></font>&#8220;WSDL stands for Web Services Dsescription Langauge. There is WSDL.exe that creates a .wsdl Files which defines how an XML Web service behaves and instructs clients as to how to interact with the service.<br />
eg: wsdl <a target="_top" href="http://localhost/WebServiceName.asmx">http://LocalHost/WebServiceName.asmx</a>&#8220;</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660033">Where on the Internet would you look for Web Services?<br />
</font></strong><a target="_top" href="http://www.uddi.org/">www.uddi.org</a></font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660033">What does WSDL stand for?<br />
</font></strong>Web Services Description Language</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660033">True or False: To test a Web service you must create a windows application or Web application to consume this service?<br />
</font></strong>False.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660033">What are the various ways of accessing a web service ?<br />
</font></strong>1.Asynchronous Call<br />
  Application can make a call to the Webservice and then continue todo watever oit  wants to do.When the service is ready it will notify the application.Application  can use BEGIN and END method to make asynchronous call to the webmethod.We can use  either a WaitHandle or a Delegate object when making asynchronous call.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">The WaitHandle class share resources between several objects. It provides several  methods which will wait for the resources to become available</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">The easiest and most powerful way to to implement an asynchronous call is using a  delegate object. A delegate object wraps up a callback function. The idea is to  pass a method in the invocation of the web method. When the webmethod has finished  it will call this callback function to process the result</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">2.Synchronous Call<br />
Application has to wait until execution has completed.</font></font></p>
<p><font size="2" face="Arial"></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#660000">What are VSDISCO files?<br />
</font></strong>VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns   references to all ASMX and DISCO files in the host directory and any subdirectories not noted in &lt;EXCLUDE&gt;elements:</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><br />
            <br />
                &lt;DYNAMICDISCOVERY<br />
                  xmlns=&#8221;urn:schemas-dynamicdiscovery:disco.2000-03-17&#8243;&gt;<br />
                  &lt;EXCLUDE path=&#8221;_vti_cnf&#8221; /&gt;<br />
                  &lt;EXCLUDE path=&#8221;_vti_pvt&#8221; /&gt;<br />
                  &lt;EXCLUDE path=&#8221;_vti_log&#8221; /&gt;<br />
                  &lt;EXCLUDE path=&#8221;_vti_script&#8221; /&gt;<br />
                  &lt;EXCLUDE path=&#8221;_vti_txt&#8221; /&gt;<br />
                &lt;/DYNAMICDISCOVERY&gt;   </font></font></p>
<p><font size="2" face="Arial"></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#990000">How does dynamic discovery work?</font><br />
</strong>ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host  directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><br />
Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line   in the &lt;HTTPHANDLERS&gt;section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET  user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.</p>
<p></font></font><font size="2" color="#660033" face="Arial"><strong>Is it possible to prevent a browser from caching an ASPX page?</strong></font></p>
<p><font size="2" face="Arial"><font color="#000000">Just call SetNoStore on the HttpCachePolicy object exposed through the Response object&#8217;s Cache property, as demonstrated here:<br />
 <br />
        &lt;%@ Page Language=&#8221;C#&#8221; %&gt;<br />
       <br />
         <br />
            &lt;%<br />
              Response.Cache.SetNoStore ();<br />
              Response.Write (DateTime.Now.ToLongTimeString ());<br />
            %&gt;<br />
         <br />
          </font></font></p>
<p><font size="2" face="Arial"><font color="#000000">SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.</font></font></p>
<p><font size="2" color="#990000" face="Arial"><strong>What does AspCompat=&#8221;true&#8221; mean and when should I use it?</strong></font></p>
<p><font size="2" face="Arial"><font color="#000000">AspCompat is an aid in migrating ASP pages to ASPX pages. It defaults to false but should be set to true in any ASPX file that creates apartment-threaded COM objects&#8211;that is, COM objects registered ThreadingModel=Apartment. That includes all COM objects written with  Visual Basic 6.0. AspCompat should also be set to true (regardless of threading  model)  if the page creates COM objects that access intrinsic ASP objects such as Request and Response. The following directive sets AspCompat to true:</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">         &lt;%@ Page AspCompat=&#8221;true&#8221; %&gt;  </font></font></p>
<p><font size="2" face="Arial"><font color="#000000">Setting AspCompat to true does two things. First, it makes intrinsic ASP objects available      to the COM components by placing unmanaged wrappers around the equivalent ASP.NET objects. Second, it improves the performance of calls that the page places to apartment- threaded COM objects by ensuring that the page (actually, the thread that processes the  request for the page) and the COM objects it creates share an apartment. AspCompat=&#8221;true&#8221; forces ASP.NET request threads into single-threaded apartments (STAs). If those threads create COM objects marked ThreadingModel=Apartment, then the objects are created in the same STAs as the threads that created them. Without AspCompat=&#8221;true,&#8221; request threads run in a multithreaded apartment (MTA) and each call to an STA-based COM object incurs a performance hit when it&#8217;s  marshaled across apartment boundaries.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000">Do not set AspCompat to true if your page uses no COM objects or if it uses COM objects that don&#8217;t access ASP intrinsic objects and that are registered ThreadingModel=Free or  ThreadingModel=Both.</font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#990000">Can two different programming languages be mixed in a single ASMX file? </font><br />
</strong>No.  </font></font></p>
<p><font size="2" face="Arial"><font color="#000000"><strong><font color="#990000">What namespaces are imported by default in ASMX files? </font><br />
</strong>The following namespaces are imported by default. Other namespaces must be imported manually.· System, System.Collections,System.ComponentModel,System.Data, System.Diagnostics,System.Web,System.Web.Services  </font></font></p>
<p><font size="2" face="Arial"><font color="#000000">How do I provide information to the Web Service when the information is required as a SOAP Header?<br />
The key here is the Web Service proxy you created using wsdl.exe or through Visual Studio .NET&#8217;s Add Web Reference menu option. If you happen to download a WSDL file for a Web Service that requires a SOAP header, .NET will create a SoapHeader class in the proxy source file. Using the previous example:    <br />
      public class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol<br />
        {   <br />
            public AuthToken AuthTokenValue;       <br />
       <br />
        [System.Xml.Serialization.XmlRootAttribute(Namespace=&#8221;<a target="_top" href="http://tempuri.org/">http://tempuri.org/</a>&#8220;, IsNullable=false)]       <br />
            public class AuthToken : SoapHeader {        public string Token;    }}  <br />
    <br />
In this case, when you create an instance of the proxy in your main application file, you&#8217;ll also create an instance of the AuthToken class and assign the string:    <br />
     Service1 objSvc = new Service1();<br />
     processingobjSvc.AuthTokenValue = new AuthToken();<br />
     objSvc.AuthTokenValue.Token = &lt;ACTUAL token value&gt;;<br />
     Web Servicestring strResult = objSvc.MyBillableWebMethod();   </font></font></p>
<p><font size="2" color="#990033" face="Arial"><strong>What is WSDL?</strong></font></p>
<p><font size="2" face="Arial"><font color="#000000">WSDL is the Web Service Description Language, and it is implemented as a specific XML vocabulary. While it&#8217;s very much more complex than what can be described here, there are two important aspects to WSDL with which you should be aware. First, WSDL provides instructions to consumers of Web Services to describe the layout and contents of the SOAP packets  the Web Service intends to issue. It&#8217;s an interface description document, of sorts. And second, it isn&#8217;t intended that you  read and interpret the WSDL. Rather, WSDL should be processed by machine, typically to generate proxy source code (.NET) or create dynamic proxies on the fly (the SOAP Toolkit or Web Service Behavior).  </font></font></p>
<p><font face="Arial"><font size="2"><strong><font color="#990000" face="Geneva, Arial, Sans-serif">What is a Windows Service and how does its lifecycle differ from a &#8220;standard&#8221; EXE?</font></strong><br />
Windows service is a application that runs in the background. It is equivalent to a NT service.<br />
The executable created is not a Windows application, and hence you can&#8217;t just click and run it . it needs to be installed as a service, VB.Net has a facility where we can add an installer to our program and then use a utility to install the service. Where as this is not the case with standard exe</font></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong><font color="#990033">How can a win service developed in .NET be installed or used in Win98?<br />
</font></strong>Windows service cannot be installed on Win9x machines even though the .NET framework runs on machine.</font></p>
<p><font size="2" color="#990000" face="Arial"><strong>Can you debug a Windows Service? How ? </strong></font></p>
<p><font size="2" face="Arial">Yes we can debug a Windows Service.</font></p>
<p><font size="2" face="Arial">Attach the WinDbg debugger to a service after the service starts   <br />
This method is similar to the method that you can use to attach a debugger to a process and then debug a process.   <br />
Use the process ID of the process that hosts the service that you want to debug   <br />
1 To determine the process ID (PID) of the process that hosts the service that you want to debug, use one of the following methods.  <br />
 • Method 1: Use the Task Manager <br />
  a. Right-click the taskbar, and then click Task Manager. The Windows Task Manager dialog box appears.<br />
  b. Click the Processes tab of the Windows Task Manager dialog box.<br />
  c. Under Image Name, click the image name of the process that hosts the service that you want to debug. Note the process ID of this process as specified by the value of the corresponding PID field.<br />
 • Method 2: Use the Task List Utility (tlist.exe) <br />
  a. Click Start, and then click Run. The Run dialog box appears.<br />
  b. In the Open box, type cmd, and then click OK.<br />
  c. At the command prompt, change the directory path to reflect the location of the tlist.exe file on your computer.<br />
   <br />
   Note The tlist.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows<br />
  d. At the command prompt, type tlist to list the image names and the process IDs of all processes that are currently running on your computer.<br />
   <br />
   Note Make a note of the process ID of the process that hosts the service that you want to debug.</font></p>
<p><font size="2" face="Arial">2 At a command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.  <br />
   <br />
 Note If a command prompt is not open, follow steps a and b of Method 1. The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.  <br />
3 At the command prompt, type windbg –p ProcessID to attach the WinDbg debugger to the process that hosts the service that you want to debug.  <br />
   <br />
 Note ProcessID is a placeholder for the process ID of the process that hosts the service that you want to debug.  <br />
  </font></p>
<p><font size="2" face="Arial">Use the image name of the process that hosts the service that you want to debug<br />
   <br />
You can use this method only if there is exactly one running instance of the process that hosts the service that you want to run. To do this, follow these steps:   <br />
1 Click Start, and then click Run. The Run dialog box appears.  <br />
2 In the Open box, type cmd, and then click OK to open a command prompt.  <br />
3 At the command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.  <br />
   <br />
 Note The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.  <br />
4 At the command prompt, type windbg –pn ImageName to attach the WinDbg debugger to the process that hosts the service that you want to debug.  <br />
   <br />
 NoteImageName is a placeholder for the image name of the process that hosts the service that you want to debug. The &#8220;-pn&#8221; command-line option specifies that the ImageName command-line argument is the image name of a process.  <br />
back to the top   </font></p>
<p><font size="2" face="Arial">Start the WinDbg debugger and attach to the process that hosts the service that you want to debug<br />
   <br />
1 Start Windows Explorer.  <br />
2 Locate the windbg.exe file on your computer.  <br />
   <br />
 Note The windbg.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows  <br />
3 Run the windbg.exe file to start the WinDbg debugger.  <br />
4 On the File menu, click Attach to a Process to display the Attach to Process dialog box.  <br />
5 Click to select the node that corresponds to the process that hosts the service that you want to debug, and then click OK.  <br />
6 In the dialog box that appears, click Yes to save base workspace information. Notice that you can now debug the disassembled code of your service.  </font></p>
<p align="left"><font size="2" face="Arial">Configure a service to start with the WinDbg debugger attached   <br />
You can use this method to debug services if you want to troubleshoot service-startup-related problems.   <br />
1 Configure the &#8220;Image File Execution&#8221; options. To do this, use one of the following methods:  <br />
 • Method 1: Use the Global Flags Editor (gflags.exe) <br />
  a. Start Windows Explorer.<br />
  b. Locate the gflags.exe file on your computer.<br />
   <br />
   Note The gflags.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows.<br />
  c. Run the gflags.exe file to start the Global Flags Editor.<br />
  d. In the Image File Name text box, type the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.<br />
  e. Under Destination, click to select the Image File Options option.<br />
  f. Under Image Debugger Options, click to select the Debugger check box.<br />
  g. In the Debugger text box, type the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:\Program Files\Debugging Tools for Windows\windbg.exe<br />
  h. Click Apply, and then click OK to quit the Global Flags Editor.<br />
 • Method 2: Use Registry Editor <br />
  a. Click Start, and then click Run. The Run dialog box appears.<br />
  b. In the Open box, type regedit, and then click OK to start Registry Editor.<br />
  c. Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.<br />
   <br />
   In Registry Editor, locate, and then right-click the following registry subkey:<br />
   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options<br />
  d. Point to New, and then click Key. In the left pane of Registry Editor, notice that New Key #1 (the name of a new registry subkey) is selected for editing.<br />
  e. Type ImageName to replace New Key #1, and then press ENTER.<br />
   <br />
   Note ImageName is a placeholder for the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.<br />
  f. Right-click the registry subkey that you created in step e.<br />
  g. Point to New, and then click String Value. In the right pane of Registry Editor, notice that New Value #1, the name of a new registry entry, is selected for editing.<br />
  h. Replace New Value #1 with Debugger, and then press ENTER.<br />
  i. Right-click the Debugger registry entry that you created in step h, and then click Modify. The Edit String dialog box appears.<br />
  j. In the Value data text box, type DebuggerPath, and then click OK.<br />
   <br />
   Note DebuggerPath is a placeholder for the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:\Program Files\Debugging Tools for Windows\windbg.exe<br />
2 For the debugger window to appear on your desktop, and to interact with the debugger, make your service interactive. If you do not make your service interactive, the debugger will start but you cannot see it and you cannot issue commands. To make your service interactive, use one of the following methods:  <br />
 • Method 1: Use the Services console <br />
  a. Click Start, and then point to Programs.<br />
  b. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears.<br />
  c. In the right pane of the Services console, right-click ServiceName, and then click Properties.<br />
   <br />
   Note ServiceName is a placeholder for the name of the service that you want to debug.<br />
  d. On the Log On tab, click to select the Allow service to interact with desktop check box under Local System account, and then click OK.<br />
 • Method 2: Use Registry Editor <br />
  a. In Registry Editor, locate, and then click the following registry subkey:<br />
   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName<br />
   Note Replace ServiceName with the name of the service that you want to debug. For example, if you want to debug a service named MyService, locate and then click the following registry key:<br />
   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService<br />
  b. Under the Name field in the right pane of Registry Editor, right-click Type, and then click Modify. The Edit DWORD Value dialog box appears.<br />
  c. Change the text in the Value data text box to the result of the binary OR operation with the binary value of the current text and the binary value, 0&#215;00000100, as the two operands. The binary value, 0&#215;00000100, corresponds to the SERVICE_INTERACTIVE_PROCESS constant that is defined in the WinNT.h header file on your computer. This constant specifies that a service is interactive in nature.<br />
3 When a service starts, the service communicates to the Service Control Manager how long the service must have to start (the time-out period for the service). If the Service Control Manager does not receive a &#8220;service started&#8221; notice from the service within this time-out period, the Service Control Manager terminates the process that hosts the service. This time-out period is typically less than 30 seconds. If you do not adjust this time-out period, the Service Control Manager ends the process and the attached debugger while you are trying to debug. To adjust this time-out period, follow these steps:  <br />
 a. In Registry Editor, locate, and then right-click the following registry subkey: <br />
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control <br />
 b. Point to New, and then click DWORD Value. In the right pane of Registry Editor, notice that New Value #1 (the name of a new registry entry) is selected for editing. <br />
 c. Type ServicesPipeTimeout to replace New Value #1, and then press ENTER. <br />
 d. Right-click the ServicesPipeTimeout registry entry that you created in step c, and then click Modify. The Edit DWORD Value dialog box appears. <br />
 e. In the Value data text box, type TimeoutPeriod, and then click OK <br />
   <br />
  Note TimeoutPeriod is a placeholder for the value of the time-out period (in milliseconds) that you want to set for the service. For example, if you want to set the time-out period to 24 hours (86400000 milliseconds), type 86400000. <br />
 f. Restart the computer. You must restart the computer for Service Control Manager to apply this change. <br />
4 Start your Windows service. To do this, follow these steps:  <br />
 a. Click Start, and then point to Programs. <br />
 b. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears. <br />
 c. In the right pane of the Services console, right-click ServiceName, and then click Start. <br />
   <br />
  Note ServiceName is a placeholder for the name of the service that you want to debug. </font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=50</wfw:commentRss>
		</item>
		<item>
		<title>ASP.Net Interview Questions 8</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=49</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=49#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:13:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.Net Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=49</guid>
		<description><![CDATA[What is view state and use of it?
The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which  allows you to program accordingly.
What are [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Arial"><strong><font color="#800000">What is view state and use of it?<br />
</font></strong>The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which  allows you to program accordingly.</p>
<p><strong><font color="#800000">What are user controls and custom controls?<br />
</font>Custom controls:</strong><br />
 A control authored by a user or a third-party software vendor that does not belong to   the .NET Framework class library. This is a generic term that includes user controls. A  custom server control is used in Web Forms (ASP.NET pages). A custom client control is used  in Windows Forms applications.</p>
<p><strong>User Controls:<br />
</strong>In ASP.NET: A user-authored server control that enables an ASP.NET page to be re-used   as a server control. An ASP.NET user control is authored declaratively  and persisted as a  text file with an .ascx extension. The ASP.NET page framework compiles a user control on  the fly to a class that derives from the        System.Web.UI.UserControl class.</p>
<p><font color="#800000"><strong>What are the validation controls?</strong><br />
</font>A set of server controls included with ASP.NET that test user input in HTML and Web server  controls for programmer-defined requirements. Validation controls perform input checking in server code. If the user is working with a browser that supports DHTML, the validation  controls can also perform validation using client script.</p>
<p><strong><font color="#800000">What&#8217;s the difference between Response.Write() andResponse.Output.Write()?<br />
</font></strong>The latter one allows you to write formattedoutput.</p>
<p><strong><font color="#800000">What methods are fired during the page load? Init()<br />
</font></strong> When the page is instantiated, Load() - when the page is loaded into server  memory,PreRender () - the brief moment before the page is displayed to the user  as HTML, Unload() - when page finishes loading.</p>
<p><strong><font color="#800000">Where does the Web page belong in the .NET Framework class hierarchy?<br />
</font></strong>System.Web.UI.Page</p>
<p><strong><font color="#800000">Where do you store the information about the user&#8217;s locale?<br />
</font></strong>System.Web.UI.Page.Culture</p>
<p><strong><font color="#800000">What&#8217;s the difference between Codebehind=&#8221;MyCode.aspx.cs&#8221; and Src=&#8221;MyCode.aspx.cs&#8221;?<br />
</font></strong>CodeBehind is relevant to Visual Studio.NET only.</p>
<p><strong><font color="#800000">What&#8217;s a bubbled event?</font><br />
</strong>When you have a complex control, likeDataGrid, writing an event processing routine for each object (cell, button,row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.<br />
Suppose you want a certain ASP.NET function executed on MouseOver over a certain button.</p>
<p><strong><font color="#800000">Where do you add an event handler?<br />
</font></strong>It&#8217;s the Attributesproperty, the Add function inside that property.            <br />
e.g. btnSubmit.Attributes.Add(&#8221;onMouseOver&#8221;,&#8221;someClientCode();&#8221;)</p>
<p><strong><font color="#800000">What data type does the RangeValidator control support?<br />
</font></strong>Integer,String and Date.</p>
<p><strong><font color="#800000">What are the different types of caching?</font><br />
</strong>Caching is a technique widely used in computing to increase performance by keeping frequently accessed or expensive data in memory. In context of web application, caching is used to retain the pages or data across HTTP requests and reuse them without the expense of recreating them.ASP.NET has 3 kinds of caching strategiesOutput CachingFragment CachingData     </font></p>
<p><font size="2" face="Arial"><strong>CachingOutput Caching: </strong>Caches the dynamic output generated by a request. Some times it is useful to cache  the output of a website even for a minute, which will result in a better  performance. For caching the whole page the page should have OutputCache directive.&lt;%@ OutputCache Duration=&#8221;60&#8243; VaryByParam=&#8221;state&#8221; %&gt;</font></p>
<p><font size="2" face="Arial"><strong>Fragment Caching:</strong> Caches the portion of the  page generated by the request. Some times it is not practical to cache the entire page, in such cases we can cache a portion of page&lt;%@ OutputCache Duration=&#8221;120&#8243; VaryByParam=&#8221;CategoryID;SelectedID&#8221;%&gt;</font></p>
<p><font size="2" face="Arial"><strong>Data Caching:</strong> Caches the objects programmatically. For     data caching asp.net provides a cache object for eg: cache[&#8221;States&#8221;] = dsStates;</p>
<p><strong><font color="#800000">What do you mean by authentication and authorization?<br />
</font></strong>Authentication is the process of validating a user on the credentials (username and     password) and authorization performs after authentication. After Authentication a user will     be verified for performing the various tasks, It access is limited it is known as       authorization.</p>
<p><strong><font color="#800000">What are different types of directives in .NET?</font><br />
@Page</strong>: Defines page-specific attributes used by the ASP.NET page parser and compiler. Can       be included only in .aspx files &lt;%@ Page AspCompat=&#8221;TRUE&#8221; language=&#8221;C#&#8221; %&gt;  <br />
<strong>@Control</strong>:Defines control-specific attributes used by the ASP.NET page parser and        compiler. Can be included only in .ascx files. &lt;%@ Control Language=&#8221;VB&#8221; EnableViewState=&#8221;false&#8221; %&gt;<br />
<strong>@Import</strong>: Explicitly imports a namespace into a page or user control. The Import         directive cannot have more than one namespace attribute. To import multiple     namespaces,     use multiple @Import directives. &lt;% @ Import Namespace=&#8221;System.web&#8221; %&gt;<br />
<strong>@Implements</strong>: Indicates that the current page or user control implements the specified .NET      framework interface.&lt;%@ Implements Interface=&#8221;System.Web.UI.IPostBackEventHandler&#8221; %&gt;<br />
<strong>@Register</strong>: Associates aliases with namespaces and class names for concise notation in   custom server control syntax.&lt;%@ Register Tagprefix=&#8221;Acme&#8221; Tagname=&#8221;AdRotator&#8221; Src=&#8221;AdRotator.ascx&#8221; %&gt;<br />
<strong>@Assembly</strong>: Links an assembly to the current page during compilation, making all         the     assembly&#8217;s classes and interfaces available for use on the      page. &lt;%@ Assembly Name=&#8221;MyAssembly&#8221; %&gt;&lt;%@ Assembly Src=&#8221;MySource.vb&#8221; %&gt;<br />
<strong>@OutputCache</strong>: Declaratively controls the output caching policies of an ASP.NET page or a        user control contained in a page&lt;%@ OutputCache Duration=&#8221;#ofseconds&#8221; Location=&#8221;Any | Client | Downstream | Server | None&#8221; Shared=&#8221;True | False&#8221; VaryByControl=&#8221;controlname&#8221; VaryByCustom=&#8221;browser | customstring&#8221; VaryByHeader=&#8221;headers&#8221; VaryByParam=&#8221;parametername&#8221; %&gt;<br />
<strong>@Reference</strong>: Declaratively indicates that another user control or page source file               should be dynamically compiled and linked against the page in which this directive is   declared.</font></p>
<p><font face="Arial"><font size="2"><strong><font color="#800000">How do I debug an ASP.NET application that wasn&#8217;t written with Visual Studio.NET and that doesn&#8217;t use code-behind?<br />
</font></strong>Start the DbgClr debugger that comes with the .NET Framework SDK, open the file containing      the code you want to debug, and set your breakpoints. Start the ASP.NET application. Go back to DbgClr, choose Debug Processes from the Tools menu, and select  aspnet_wp.exe from  the list of processes. (If aspnet_wp.exe doesn&#8217;t appear in the list,check the &#8220;Show system      processes&#8221; box.) Click the Attach button to attach to aspnet_wp.exe and begin debugging.<br />
Be sure to enable debugging in the ASPX file before debugging it with DbgClr. You can   enable tell ASP.NET to build debug executables by placing a<br />
&lt;%@ Page Debug=&#8221;true&#8221; %&gt;   statement at the top of an ASPX file or a   &lt;COMPILATION debug=&#8221;true&#8221; /&gt;statement in a Web.config file.<br />
 <br />
</font><font size="2"><strong><font color="#800000">Can a user browsing my Web site read my Web.config or Global.asax files?</font><br />
</strong>No. The &lt;HTTPHANDLERS&gt;section of Machine.config, which holds the master configuration  settings for ASP.NET, contains entries that map ASAX files, CONFIG files, and selected  other file types to an HTTP handler named HttpForbiddenHandler, which fails attempts to retrieve the associated file. You can modify it by editing  Machine.config or including an section in a local Web.config file.</p>
<p></font><font size="2"><strong><font color="#800000">What&#8217;s the difference between Page.RegisterClientScriptBlock and Page.RegisterStartupScript?<br />
</font></strong>RegisterClientScriptBlock is for returning blocks of client-side script containing functions. RegisterStartupScript is for returning blocks of client-script not   packaged in functions-in other words, code that&#8217;s to execute when the page is loaded. The latter positions script blocks near the end of the document so elements on the page that the script interacts are loaded before the script runs.&lt;%@ Reference Control=&#8221;MyControl.ascx&#8221; %&gt;<br />
</font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=49</wfw:commentRss>
		</item>
		<item>
		<title>ASP.Net Interview Questions 7</title>
		<link>http://oopsconcepts.com/interviewquestions/?p=48</link>
		<comments>http://oopsconcepts.com/interviewquestions/?p=48#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:12:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[ASP.Net Questions]]></category>

		<guid isPermaLink="false">http://oopsconcepts.com/interviewquestions/?p=48</guid>
		<description><![CDATA[Is it necessary to lock application state before accessing it?
Only if you&#8217;re performing a multistep update and want the update to be treated as an atomic     operation. Here&#8217;s an example:
                Application.Lock ();
                Application[&#8221;ItemsSold&#8221;] = (int) Application[&#8221;ItemsSold&#8221;] + 1;
                Application[&#8221;ItemsLeft&#8221;] = (int) Application[&#8221;ItemsLeft&#8221;] - 1;
                Application.UnLock (); 
By locking application state before updating it and unlocking it [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Is it necessary to lock application state before accessing it?<br />
</strong>Only if you&#8217;re performing a multistep update and want the update to be treated as an atomic     operation. Here&#8217;s an example:<br />
                Application.Lock ();<br />
                Application[&#8221;ItemsSold&#8221;] = (int) Application[&#8221;ItemsSold&#8221;] + 1;<br />
                Application[&#8221;ItemsLeft&#8221;] = (int) Application[&#8221;ItemsLeft&#8221;] - 1;<br />
                Application.UnLock (); <br />
By locking application state before updating it and unlocking it afterwards, you ensure  that another request being processed on another thread doesn&#8217;t read application state   at exactly the wrong time and see an inconsistent view of it. If I update session state, should I lock it, too? Are concurrent accesses by multiple requests executing on multiple threads a concern with session state?<br />
Concurrent accesses aren&#8217;t an issue with session state, for two reasons. One, it&#8217;s unlikely that two requests from the same user will overlap. Two, if they do overlap, ASP.NET locks down session state during request processing so that two threads can&#8217;t touch it at once. Session state is locked down when the HttpApplication instance that&#8217;s processing the request fires an AcquireRequestState event and unlocked when it fires a ReleaseRequestState event.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Do ASP.NET forms authentication cookies provide any protection against replay attacks? Do they, for example, include the client&#8217;s IP  address or anything else that would distinguish the real client from an attacker?<br />
No. If an authentication cookie is stolen, it can be used by an attacker. It&#8217;s up to you to     prevent this from happening by using an encrypted communications channel (HTTPS). Authentication cookies issued as session cookies, do, however,include a time-out valid that     limits their lifetime. So a stolen session cookie can only be used in replay attacks as long as the ticket inside the cookie is valid. The default time-out interval is 30 minutes.You can change that by modifying the timeout attribute accompanying the &lt;forms&gt; element in Machine.config or a local Web.config file. Persistent authentication cookies do not  time-out and therefore are a more serious security threat if stolen.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How do I send e-mail from an ASP.NET application?</strong><br />
 <br />
        MailMessage message = new MailMessage ();<br />
        message.From = &lt;email&gt;;<br />
        message.To = &lt;email&gt;;<br />
        message.Subject = &#8220;Scheduled Power Outage&#8221;;<br />
        message.Body = &#8220;Our servers will be down tonight.&#8221;;<br />
        SmtpMail.SmtpServer = &#8220;localhost&#8221;;<br />
        SmtpMail.Send (message);</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"> MailMessage and SmtpMail are classes defined in the .NET Framework Class Library&#8217;s  System.Web.Mail namespace. Due to a security change made to ASP.NET just before it shipped,  you need to set SmtpMail&#8217;s SmtpServer property to &#8220;localhost&#8221; even though &#8220;localhost&#8221; is  the default. In addition, you must use the IIS configuration applet to enable localhost  (127.0.0.1) to relay messages through the local SMTP service.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are VSDISCO files?</strong></font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns   references to all ASMX and DISCO files in the host directory and any subdirectories not         noted in &lt;exclude&gt; elements:<br />
             &lt;?xml version=&#8221;1.0&#8243; ?&gt;<br />
                &lt;dynamicDiscovery<br />
                  xmlns=&#8221;urn:schemas-dynamicdiscovery:disco.2000-03-17&#8243;&gt;<br />
                  &lt;exclude path=&#8221;_vti_cnf&#8221; /&gt;<br />
                  &lt;exclude path=&#8221;_vti_pvt&#8221; /&gt;<br />
                  &lt;exclude path=&#8221;_vti_log&#8221; /&gt;<br />
                  &lt;exclude path=&#8221;_vti_script&#8221; /&gt;<br />
                  &lt;exclude path=&#8221;_vti_txt&#8221; /&gt;<br />
                &lt;/dynamicDiscovery&gt;   </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How does dynamic discovery work?</strong><br />
ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host  directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.<br />
Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line   in the &lt;httpHandlers&gt; section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET  user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.<br />
 <br />
<strong>Is it possible to prevent a browser from caching an ASPX page?<br />
</strong>Just call SetNoStore on the HttpCachePolicy object exposed through the Response object&#8217;s Cache property, as demonstrated here:<br />
 <br />
        &lt;%@ Page Language=&#8221;C#&#8221; %&gt;<br />
        &lt;html&gt;<br />
          &lt;body&gt;<br />
            &lt;%<br />
              Response.Cache.SetNoStore ();<br />
              Response.Write (DateTime.Now.ToLongTimeString ());<br />
            %&gt;<br />
          &lt;/body&gt;<br />
        &lt;/html&gt;  </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What does AspCompat=&#8221;true&#8221; mean and when should I use it?</strong><br />
AspCompat is an aid in migrating ASP pages to ASPX pages. It defaults to false but should be set to true in any ASPX file that creates apartment-threaded COM objects&#8211;that is, COM objects registered ThreadingModel=Apartment. That includes all COM objects written with  Visual Basic 6.0. AspCompat should also be set to true (regardless of threading  model)  if the page creates COM objects that access intrinsic ASP objects such as Request and Response. The following directive sets AspCompat to true:</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">         &lt;%@ Page AspCompat=&#8221;true&#8221; %&gt;  </font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Setting AspCompat to true does two things. First, it makes intrinsic ASP objects available      to the COM components by placing unmanaged wrappers around the equivalent ASP.NET objects. Second, it improves the performance of calls that the page places to apartment- threaded COM objects by ensuring that the page (actually, the thread that processes the  request for the page) and the COM objects it creates share an apartment. AspCompat=&#8221;true&#8221; forces ASP.NET request threads into single-threaded apartments (STAs). If those threads create COM objects marked ThreadingModel=Apartment, then the objects are created in the same STAs as the threads that created them. Without AspCompat=&#8221;true,&#8221; request threads run in a multithreaded apartment (MTA) and each call to an STA-based COM object incurs a performance hit when it&#8217;s  marshaled across apartment boundaries.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif">Do not set AspCompat to true if your page uses no COM objects or if it uses COM objects that don&#8217;t access ASP intrinsic objects and that are registered ThreadingModel=Free or  ThreadingModel=Both.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Explain the differences between Server-side and Client-side code?<br />
</strong> Server side scripting means that all the script will be executed by the server and  interpreted as needed. ASP doesn&#8217;t have some of the functionality like sockets, uploading,  etc. For these you have to make a custom components usually in VB or VC++. Client side  scripting means that the script will be executed immediately in the browser such as form field validation, clock, email validation, etc. Client side scripting is usually done in  VBScript or JavaScript. Download time, browser compatibility, and visible code - since  JavaScript and VBScript code is included in the HTML page, then anyone can see the code by viewing the page source. Also a possible security hazards for the client computer.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What type of code (server or client) is found in a Code-Behind class?</strong><br />
C#</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Should validation (did the user enter a real date) occur server-side or client-side? Why?<br />
</strong>Client-side validation because there is no need to request a server side date when you  could obtain a date from the client machine.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What are ASP.NET Web Forms? How is this technology different than what is available though ASP?<br />
</strong>Web Forms are the heart and soul of ASP.NET. Web Forms are the User Interface (UI) elements that give your Web applications their look and feel. Web Forms are similar to Windows Forms in that they provide properties, methods, and events for the controls that are placed onto  them. However, these UI elements render themselves in the appropriate markup language   required by the request, e.g. HTML. If you use Microsoft Visual Studio .NET, you will also get the familiar drag-and-drop interface used to create your UI for your Web application.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?</strong><br />
In earlier versions of IIS, if we wanted to send a user to a new Web page, the only option we had was Response.Redirect. While this method does accomplish our goal, it has several important drawbacks. The biggest problem is that this method causes each page to be treated as a separate transaction. Besides making it difficult to maintain your transactional   integrity, Response.Redirect introduces some additional headaches. First, it prevents good encapsulation of code. Second, you lose access to all of the properties in the Request  object. Sure, there are workarounds, but they&#8217;re difficult. Finally, Response.Redirect  necessitates a round trip to the client, which, on high-volume sites, causes scalability problems.<br />
As you might suspect, Server.Transfer fixes all of these problems. It does this by performing the transfer on the server without requiring a roundtrip to the client.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>How can you provide an alternating color scheme in a Repeater control?<br />
</strong>AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>Which template must you provide, in order to display data in a Repeater control?</strong><br />
ItemTemplate</font></p>
<p><font size="2" face="Geneva, Arial, Sans-serif"><strong>What event handlers can I include in Global.asax?<br />
</strong>Application_Start,Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed,  Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,<br />
Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache, Session_Start,Session_End<br />
You can optionally include &#8220;On&#8221; in any of method names. For example, you can name a BeginRequest event handler.Application_BeginRequest or Application_OnBeginRequest.You can also include event handlers in Global.asax for events fired by custom HTTP modules.Note that not all of the event handlers make sense for Web Services (they&#8217;re designed for ASP.NET applications in general, whereas .NET XML Web Services are specialized instances of an ASP.NET app). For example, the Application_AuthenticateRequest and Application_AuthorizeRequest events are designed to be used with ASP.NET Forms authentication</font></p>
]]></content:encoded>
			<wfw:commentRss>http://oopsconcepts.com/interviewquestions/?feed=rss2&amp;p=48</wfw:commentRss>
		</item>
	</channel>
</rss>

