?

Log in

How can we save all data from dataset?

Dataset has “AcceptChanges” method, which commits all the changes since last time “Acceptchanges” has been executed.

How can we check which rows have changed since dataset was loaded?

For tracking down changes, Dataset has two methods, which comes to rescue “Get Changes “and “Has Changes”.

Get Changes
Returns dataset, which are changed since it, was loaded, or since Accept changes was executed.

Has Changes
Or abandon all changes since the dataset was loaded use “Reject Changes This property indicates that has any changes been made since the dataset was loaded or accept changes method was executed.

How can we add/remove row is in “Data Table” object of “Dataset”?

“Data table” provides “NewRow” method to add new row to “Data Table”. “Data Table” has “DataRowCollection” object that has all rows in a “Data Table” object. Following are the methods provided by “DataRowCollection” object:-

Add
Adds a new row in Data Table

Remove
It removes a “Data Row” object from “Data Table”

Remove At
It removes a “Data Row” object from “Data Table” depending on index position of the “Data Table”.

How can we load multiple tables in a Dataset?

objCommand.CommandText = "Table1"
objDataAdapter.Fill(objDataSet, "Table1")
objCommand.CommandText = "Table2"
objDataAdapter.Fill(objDataSet, "Table2")


Above is a sample code, which shows how to load multiple “Data Table” objects in one “Dataset” object. Sample code shows two tables “Table1” and “Table2” in object ObjDataSet.


lstdata.DataSource = objDataSet.Tables("Table1").DefaultView

In order to refer “Table1” Data Table, use Tables collection of Datasets and the Default view object will give you the necessary output.

How can we add relation between tables in a Dataset?

Dim objRelation As DataRelation
objRelation=New
DataRelation("CustomerAddresses",objDataSet.Tables("Customer").Columns("Custid")
,objDataSet.Tables("Addresses").Columns("Custid_fk"))
objDataSet.Relations.Add(objRelation)


Relations can be added between “Data Table” objects using the “Data Relation” object. Above sample, code is trying to build a relationship between “Customer” and “Addresses” “Data table” using “Customer Addresses” “Data Relation” object.

See the following video on Dataset is a disconnect while datareader is connected: -



Click and see here for more step by step training in ADO.NET
Copy right www.questpond.com
What are Accessors and mutators in C#?

Look at the following example,

public class Customer
{
     publicint Age;
     .
     .
     .
 }


Now in the client code we will do something like this.

Customer c=new Customer();
c.Age=55;


But do you realize one thing even we can do something like this,

c.Age=563;
OR
c.Age=-65;


This is not a valid statement logically but it’s valid syntactically. Our program will just execute perfectly fine.

One of the pillar of Object oriented principle called Encapsulation let us protect our data by creating a wrapper around our data, logic etc. by means of functions, classes etc. In short Encapsulation also let us protects our data.

Usually we will do something like this.

public class Customer
{
       privateint Age; // data is private
       .
       .
       .
       publicintGetAge() // Data is exposed to outside world via public method
       {
               Return Age;
       }
       publicvoid SetAge(intpAge) // Updating of data is only possible via public method
       {
             If(pAge>0 &&pAge<100)
             {
                    Age=pAge;
             }
             else
             {
                   throw new Exception(“Invalid Age”);
             }
        }
 }


Now our data is protected.

Client code will look like this.

Customer c=new Customer();
c.SetAge(55);
Console.WriteLine(c.GetAge());

c.SetAge(965); // It will throw exception


In the above code snippet GetAge function which usually return the data is called Accessor method and SetAge function which updates data is called Mutator method.

Good news?

Now we are in C# things become much simpler. We can make use of properties instead of creating two functions.

public class Customer
{
       privateintpAge; .
       .
       .
       publicintAge()
       {
               get
               {
                    //Accessor
                    returnpAge;
               }
               set
               {
                   //Mutator
                   If(value>0 && value<100)
                   {
                           pAge=value;
                   }
                   else
                   {
                           throw new Exception(“Invalid Age”);
                   }
              }
        }
 }


Client code will look like this,

Customer c=new Customer();
c.Age=55;
Console.WriteLine(c.Age);

c.Age = 965; // It will throw exception


For technical trainings on various topics like WCF(Windows Communication Foundation), MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

Click and see here for more .NET training.

Copy right www.questpond.com
How security works in WCF?

In WCF security is by default enabled in wsHttpBinding and NetHttpBinding.
Enabled means all three aspects of security (CIA) is automatically provided by bindings.


Let’s understand how.

1. C – Confidentiality – Data can be viewed by only intended recipient.
     It is done by means of encryption. Data (Messages) to be transferred will be encrypted.
     Even if someone get the message he will not be able to understand it.

2. I – Integrity – Data should not be tempered.
     It is done by means of signing. Data (messages) to be transferred will be signed. If
     someone modifies the data in between receiver easily come to know about that.

3. A – Authentication – User should validate his/her identity.
     By default all the binding except basic provides windows authentication. It means every
     service call will be authenticated automatically. While making call automatically clients
     windows credentials will be passed along which will be automatically get validated in
     service end. In case he is not a valid AD – Active directory user, his/her request won’t get
     processed.

For technical trainings on various topics like WCF(Windows Communication Foundation), MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

See following video on WCF(Windows Communication Foundation) Concurency and throttling: -
Copy right www.questpond.com
How to invoke WCF service asynchronously?

As a service developer we just simply create the service, host it and expose the endpoints. Now whether those functions should be called synchronous or asynchronously is client’s lookout.

When the proxy class of our service get generated in the client side, async version of all our service methods also get generated automatically.
For example : If our service contain methods such as GetString, GetCustomer then our proxy class will contain four methods, GetString,GetCustomer,GetStringAsync,GetCustomerAsync.

There are two approaches normally a .net developer can follow,

  1. Event based approach

  2. Task based approach

1. Event based approach

Both the asynchronous methods will never return anything. Return type will be void. Instead on completion, some events will be raised.

Complete code:

privatevoid button1_Click(object sender, EventArgs e)
{
   FirstClient c = newFirstClient("WSHttpBinding_IFirst");
   c.GetStringCompleted += c_GetStringCompleted;
   c.GetStringAsync();
   .
   .
}
.
.
.
.
voidc_GetStringCompleted(object sender, GetStringCompletedEventArgs e)
{
label2.Text = e.Result;
}

2. Task based approach

In this approach C# 5.0 asycn await pattern will be used. Here asynchronous methods will return “Task” object instead of direct return value which can be awaited later

privateasyncvoid button1_Click(object sender, EventArgs e)
{
       FirstClient c = newFirstClient("WSHttpBinding_IFirst");
       Task<string> r=c.GetStringAsync();
   .
   .
   .
label2.Text += "\n" + await r;
}

For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

See following video on WCF concurrency and throttling: -



Click and see here for more step by step learning WCF(Windows Communication Foundation).
Copy right www.questpond.com
What is Namespace?

Namespace does two basic functionalities:-

  • It logically groupsclasses, for instance System.Web.UI logically groups UI related features like textboxes, list control etc.

  • In Object Oriented world, many times it is possible that programmers will use the same class name. Qualifying NameSpace with class names avoids this collision.

What is Difference between NameSpace and Assembly?

Following are the differences between namespace and assembly:

  • Assembly is physical grouping of logical units, Namespace, logically groupsclasses.

  • Namespace can span multiple assemblies while assembly is a physical unit like EXE , DLL etc.

What is ILDASM?

ILDASM is a simple tool which helps you to view IL code of a DLL or EXE. In order to view  IL code using ILDASM , go to visual studio command prompt and run “ILDASM.EXE”. Once ILDASM is running you view the IL code.

What is Manifest?

Assembly metadata is stored in Manifest. Manifest contains metadata which describes the following things :-

  • Version of assembly.

  • Security identity.

  • Scope of the assembly.

  • Resolve references to resources and classes.

The assembly manifest is stored in the DLL itself.

Where is the version information stored of an assembly?

Version information is stored in assembly inside the manifest.

Is versioning applicable to private assemblies?

Yes, versioning is applicable to private assemblies also.

See following video on to check assembly manifest for supported CLR version: -



Click and see here for more basics of .NET.
Copy right www.questpond.com
Tell me something about PerSession instance context mode in WCF?

When we set instance context mode as PerSession in WCF, for every channel object or proxy object client creates a dedicated service instance will be created.

What happens by that?

Our service become state full. Values of the variables updated during subsequent service call will be maintained.

Is it the default instance context mode?

Yes it is, considering binding supports session full endpoints. For example when your binding is netTcpEndpoint or wsHttpBindingPerInstance is default but when its basicHttpBinding default one will be percall because PerInstance is not supported over there?

Does WsHttpBinding supports sessions all the time?

No, it supports only if security is enabled. Best point is in case of WSHttpBinding security is be default turned on.

What if I don’t want security but wants session?

You have to enable reliable messaging at least. Reliable messaging is not enabled by default.

How the server differentiates between different sessions in case of per instance?

It will be with the help of sessionId. SessionId will be created for a client when he create the proxy or channel instance for first time.

Is it possible to get current session Id in service?

Yes, using OperationContext.Current.SessionId

For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

See following video on WCF concurrency and throttling: -



Click and see here for more advanced training in .NET on WCF(Windows Communication Foundation) .
Copy right www.questpond.com
How do you fill the dataset?

Create object of data adapter and call the fill command method of the adapter.

SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset);


How can we save all data from dataset?

Dataset has “AcceptChanges” method, which commits all the changes since last time “Acceptchanges” has been executed.

How can we load multiple tables in a Dataset?

objCommand.CommandText = "Table1"
objDataAdapter.Fill(objDataSet, "Table1")
objCommand.CommandText = "Table2"
objDataAdapter.Fill(objDataSet, "Table2")
 

Above is a sample code, which shows how to load multiple “Data Table” objects in one “Dataset” object. Sample code shows two tables “Table1” and “Table2” in object ObjDataSet.

lstdata.DataSource = objDataSet.Tables("Table1").DefaultView

In order to refer “Table1” Data Table, use Tables collection of Datasets and the Default view object will give you the necessary output.

How can we add relation between tables in a Dataset?

Dim objRelation As DataRelation
objRelation=New
DataRelation("CustomerAddresses",objDataSet.Tables("Customer").Columns("Custid")
,objDataSet.Tables("Addresses").Columns("Custid_fk"))
objDataSet.Relations.Add(objRelation)
 

Relations can be added between “Data Table” objects using the “Data Relation” object. Above sample, code is trying to build a relationship between “Customer” and “Addresses” “Data table” using “Customer Addresses” “Data Relation” object.

See following video on Dataset is a disconnect while datareader is connected: -



Click and see here for more basics on  ADO.NET.
Copy right www.questpond.com
What is the difference between data contract serializer and XML serializer?

XML Serializer

  • It follows the Opt-out approach. It means all the public properties get serialized. If you don’t want something you have to specify explicitly.

  • It serializes only properties and again only public properties with both get and set accessor.

Data contract serializer

  • It follows Opt-In approach. It means we have to explicitly specify what we want to serialize.

  • It can serialize nonpublic members and fields also.

For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

See following video on endpoints, address, contracts and bindings: -



Click and see here for more step by step learning on WCF(Windows Communication Foundation).
Copy right www.questpond.com
What is the difference between “Web farmsWeb g” and “arden”?

“Web farms” are used to have some redundancy to minimize failures and to meet heavy load demands.

It consists of two or more web server of the same configuration and they stream the same kind of contents. When any request comes there is switching / routing logic, which decides which web server from the farm, handles the request. For instance, we have two servers “Server1” and “Server2” which have the same configuration and content. Therefore, there is a special switch, which stands in between these two servers and the users and routes the request accordingly.

rout 1

Above figure explains in detail how web farm work. You can see there is a router in between which takes a request and sees which one of the server is least loaded and forwards the request to that server. Therefore, for request1 it route is server1, for request2 it routes server2, for request3 it routes to server3 and final request4 is routed to server4. So you can see because we have web farm at place server1 and server2 are loaded with two request each rather than one server loading to full. One more advantage of using this kind of architecture is if one of the servers goes down we can still run with the other server thus having 24x7 uptime.

The routing logic can be a number of different options: -

  • Round robin: Each node gets a request sent to it “in turn”. Therefore, server1 gets a request, then server2 again, then server1, then server2 again.  As shown in the above figure.

  • Least Active: Whichever node show to have the lowest number of current connects gets new connects sent to it. This is good to help keep the load balanced between the server nodes.

  • Fastest Reply: Whichever node replies faster is the one that gets new requests. This is also a good option - especially if there are nodes that might not be “equal” in performance. If one performs better than the other, then send more requests there rather than which is moving slowly?

Before we try to understand what a web garden is let’s try to understand how IIS handles processes. All requests to IIS are routed to “aspnet_wp.exe” for IIS 5.0 and “w3wp.exe” for IIS 6.0. In normal case i.e. without web garden, we have one worker process instance (“aspnet_wp.exe” / “w3wp.exe”) across all requests. This one instance of worker process uses the CPU processor as directed by the operating system.

rout 2
However, when we enable web garden for a web server it creates different instances of the worker process and each of these worker process runs on different CPU. You can see in the below diagram we have different worker process instances created which run on different CPU’s.

rout 3
In short, we can define a model in which multiple processes run on multiple CPUs in a single server machine are termed as Web garden.

How do we configure “Web Garden”?

“Web garden” can be configured by using process model settings in “machine.config” or “Web.config” file. The configuration section is named and is shown in

The following example. The process model is enabled by default (enable=”true”). Below is the snippet from config file.

<process Model
enable=”true”
timeout=”infinite”
idle Timeout=”infinite”
shutdown Timeout=”0:00:05"
requestLimit=”infinite”
requestQueueLimit=”5000"
memoryLimit=”80"
webGarden=”false”
cpuMask=”12"
userName=””
password=””
logLevel=”errors”
clientConnectedCheck=”0:00:05"
/>


From the above process model section for web garden, we are concerned with only two attributes “web garden” and “cpuMask”.

WebGarden: - Controls CPU affinity. True indicates that processes should be affinities to the corresponding CPU. The default is False.

CpuMask:- Specifies which processors on a multiprocessor server are eligible to run ASP.NET processes. The cpuMask value specifies a bit pattern that indicates the CPUs eligible to run ASP.NET threads. ASP.NET launches one worker process for each eligible CPU. If web Garden is set to false, cpuMask is ignored and only one worker process will run regardless of the number of processors in the machine. If web Garden is set to true, ASP.NET launches one worker process for each CPU that corresponds to a set bit in cpuMask. The default value of cpuMask is 0xffffffff.

Below are detail steps of how to implement web garden


  • Click Start and then click Run.

  • Type calc.exe and then click OK.

  • Go to View menu, click Scientific.

  • Go to View menu, click Binary.

  • Use zero and one to specify the processors ASP.NET can or cannot use.

Use one for the processor that you want to use for ASP.NET. Use 0 for the processor that you do not want to use for ASP.NET. For example, if you want to use the first two processors for ASP.NET of a four-processor computer, type 1100.

  • On the View menu, click Decimal. Note the decimal number.

  • Open the Web.config or machine.config file in a text editor such as Notepad. The Web.config file is located in the folder where the application is saved.

  • In the Web.config file, add the process Model configuration element under the System. Web element. Before adding <process Model> to Web.config file, the user has to make sure that the allow Definition attribute in the <process Model> section of the Web.config file is set to everywhere.

  • Add and then set the web Garden attribute of the process Model element to True.

  • Add and then set the cpuMask attribute of the process Model element to the result that is determined in your calculation.

Do not preface the number with zerox because the result of the calculation is a decimal number. The following example demonstrates the process Model element that is configured to enable only the first two processors of a four-processor computer.

<processModel
enable=”true”
webGarden=”true”
cpuMask=”12" />


Save the Web.config file. The ASP.NET application automatically restarts and uses only the specified processors.

See following video on ASP.NET Web.config transformation:



If you want to learn or want more on ASP.NET learning then follow site www.questpond.com
Copy right www.questpond.com
How can we identify that the Page is Post Back?

Page object has an “IsPostBack” property, which can be checked to know t the page is posted back.

What is the use of @ Register directives?

@Register directive informs the compiler of any custom server control added to the page.

What is the use of Smart Navigation property?

It’s a feature provided by ASP.NET to prevent flickering and redrawing when the page is posted back.

What is AppSetting Section in “Web.Config” file?

Web.config file defines configuration for a web project. Using “AppSetting” section, we can define user-defined values. Example below is a “Connection String” section, which will be used throughout the project for database connection.\

<Configuration>
<appSettings>
<add key="ConnectionString" value="server=xyz;pwd=www;database=testing" />
</appSettings>


Where is View State information stored?

In HTML Hidden Fields.

How can we create custom controls in ASP.NET?

User controls are created using .ASCX in ASP.NET. After .ASCX file is created you need to two things in order that the ASCX can be used in project:.

  • Register the ASCX control in page using the <percentage@ Register directive.Example

<%@ Register tag prefix="Accounting" Tag name="footer" Src="Footer.ascx" %>


  • Now to use the above accounting footer in page you can use the below directive.

<Accounting: footer runat="server" />

See following video on implementing ASP.NET Forms Authentication: -



Click and see here for more stuffs step by step learning ASP.NET.
Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

March 2017
S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Tags

Powered by LiveJournal.com