What is ADO.NET? State its Features.
ADO.NET (ActiveX Data Objects .NET) is a data access technology in the .NET Framework used to connect applications with databases, execute queries, and retrieve or manipulate data. It supports both connected and disconnected data access modes.
Features
- 01Supports connected and disconnected data access.
- 02Works with databases such as SQL Server, Oracle, MySQL, and Access.
- 03Supports XML natively through DataSet.
- 04Provides classes for database connection, commands, reading, and updating data.
- 05Uses namespaces such as
System.DataandSystem.Data.SqlClient.
What are Data Provider, DataSet and DataAdapter?
SqlClient for SQL Server, OleDb for Access/Excel, and Odbc for ODBC databases.Fill() to load data from the database into a DataSet and Update() to send changes back to the database.What is the purpose of the CommandBuilder class?
CommandBuilder is an ADO.NET class used to automatically generate the SQL INSERT, UPDATE, and DELETE commands for a DataAdapter. It saves the programmer from writing these commands manually.
Example
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Update(ds);
What is DataReader? State its Use.
DataReader is an ADO.NET object used to read data from a database in connected mode. It provides fast, forward-only and read-only access to the result set.
Use
- 01Used mainly for executing SELECT queries and reading records one by one.
- 02The database connection must remain open while the DataReader is being used.
- 03
ExecuteReader()is used to obtain a DataReader.
Example
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string name = dr["Name"].ToString();
}
Differentiate between ExecuteReader() and ExecuteNonQuery()
| ExecuteReader() | ExecuteNonQuery() |
|---|---|
| Used mainly for SELECT queries. | Used mainly for INSERT, UPDATE, and DELETE queries. |
| Returns a DataReader containing the result set. | Returns the number of rows affected. |
| Used when data needs to be read row by row. | Used when data needs to be inserted, updated, or deleted. |
Example:SqlDataReader dr = cmd.ExecuteReader(); | Example:int rows = cmd.ExecuteNonQuery(); |
ExecuteReader() reads data, whereas ExecuteNonQuery() performs data modification operations.
What is Client-Server Communication in ASP.NET?
Client-server communication in ASP.NET is the process in which a web browser (client) sends a request to the ASP.NET server, and the server processes it and sends a response back.
Working
Browser (Client)
↓ HTTP Request
ASP.NET Web Server
↓
Process Request
↓
HTTP Response
↓
Browser (Client)
ASP.NET mainly uses two objects:
- RequestReceives data sent by the browser, such as form values, query strings, cookies, and headers.
- ResponseSends data from the server to the browser, such as HTML, redirects, cookies, and files.
What are Request and Response Objects? State their Uses.
Response = Server → Client
What is a Cookie? Which object is used to read cookies?
A Cookie is a small piece of data stored on the client's browser by the web server. It is used for remembering information such as user preferences, login status, and session tracking.
The Request object is used to read/access cookies sent by the browser. The Response.Cookies collection is used to create or send cookies to the browser.
Example
string name = Request.Cookies["UserName"].Value;
What is a Query String? What is URL Encoding?
A Query String is data passed through the URL after a ? symbol. It is used to send small amounts of information from the client to the server.
Example
page.aspx?name=Riya&id=1
Here, name and id are query-string parameters.
URL Encoding is the process of converting special characters in a URL into a safe format so that they can be transmitted correctly.
What is Session State? Give an Example.
Session State is an ASP.NET state-management technique used to store user-specific data on the server and maintain it between different pages.
Session data is specific to each user.
Example
// Storing a value in session
Session["UserName"] = txtName.Text;
// Retrieving the value
string name = Session["UserName"].ToString();
What is Application State?
Application State is an ASP.NET state-management technique used to store data that is shared by all users throughout the entire application.
Example
Application["SiteVisitCount"] = 0;
It can be used for application-wide information such as a total visitor count.
What is State Management?
State Management is the technique of maintaining data and information between different requests/pages in an ASP.NET application.
Since HTTP is stateless, ASP.NET provides techniques such as ViewState, Session State, Application State, and Cookies to maintain state.
What is Web.config? Name its Important Sections.
Web.config is an ASP.NET configuration file used to store and manage application settings and configuration information.
Important Sections
Purpose of connectionStrings, appSettings and sessionState sections?
- connectionStringsStores database connection strings used by the ASP.NET application.
- appSettingsStores application-specific settings or key-value pairs.
- sessionStateConfigures Session State, such as session mode and timeout.
What is SiteMapPath? What is Web.sitemap?
Example: Home > Products > Mobile
What is Breadcrumb Navigation?
Breadcrumb navigation is a navigation technique that shows the current page's location within the website's hierarchy.
Example
Home > Products > Mobiles > Samsung
It helps users understand where they are on the website and easily navigate back to previous pages.
What is a Web Service? What is an ASMX Web Service?
A Web Service is a software component that allows applications to communicate and exchange data over a network.
An ASMX Web Service is a classic ASP.NET Web Service that uses the .asmx file extension. Its public methods are exposed to clients using the [WebMethod] attribute.
What is the Purpose of the <WebMethod> Attribute?
The [WebMethod] attribute is applied to a public method in an ASMX Web Service to make that method available as a Web Service operation, so that client applications can invoke it.
Example
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
Here, Add() can be called by a client application as a Web Service method.
What are SOAP and WSDL?
?wsdl.WSDL = What the Web Service provides and how to communicate with it.
What is a Proxy Class in Web Services?
A Proxy Class is a client-side class generated from the Web Service description (WSDL). It acts as a local representative of the remote Web Service, allowing the client application to call its methods as if they were local methods.
Flow
Web Service → WSDL → Proxy Class → Client Application
The proxy is generated when the client adds a Web Reference/Service Reference to the Web Service.
What is Meant by Consuming a Web Service?
Consuming a Web Service means using a Web Service from a client application by connecting to the service and calling its available methods.
Basic Process
Web Service
↓
WSDL
↓
Proxy Class
↓
Client Application
↓
Call Web Service Method
In ASP.NET, the client adds a Web Reference/Service Reference, obtains the WSDL, generates a proxy class, and then uses the proxy to call the required Web Service methods.
Example
StudentWS.StudentService svc = new StudentWS.StudentService();
int result = svc.Add(10, 20);
Here, the client is consuming the StudentService Web Service by calling its Add() method.
Explain ADO.NET Architecture. Differentiate between Connected and Disconnected Data Models.
ADO.NET (ActiveX Data Objects .NET) is a data-access technology in the .NET Framework. It provides classes for connecting to databases, executing commands, and retrieving/manipulating data using both connected and disconnected modes.
Components of ADO.NET
A set of classes designed for a particular database. Examples: SqlClient → SQL Server, OleDb → MS Access/Excel.
Establishes and manages the physical connection between the app and the database. Important methods are Open() and Close().
Executes SQL queries or stored procedures. Important methods: ExecuteReader(), ExecuteNonQuery(), ExecuteScalar().
Provides a fast, forward-only and read-only stream of data. Requires the database connection to remain open.
Bridge between the database and DataSet. Fill() loads data; Update() sends changes back.
DataSet: In-memory representation of a relational database. Works offline.
CommandBuilder: Auto-generates INSERT, UPDATE, DELETE commands for a DataAdapter.
Connected vs Disconnected Data Model
| Feature | Connected Model | Disconnected Model |
|---|---|---|
| Connection | Remains open while working | Can be closed after data is retrieved |
| Main Object | DataReader | DataSet with DataAdapter |
| Data Access | Generally reads one row at a time | Stores data in memory |
| Speed | Fast for sequential reading | Suitable for offline/in-memory work |
| Network Usage | Connection remains active | Connection is opened only when required |
| Example | Reading student records | Loading student records into a DataSet |
Explain Query String and URL Encoding with Examples. State Advantages and Limitations.
Query String
A Query String is data appended to a URL after the ? (query delimiter). It is used to pass information between pages through the URL. Multiple parameters are separated using &.
https://iqra.ac.in/Profile.aspx?id=5&name=Riya
In ASP.NET, the values can be retrieved using the Request.QueryString collection:
string id = Request.QueryString["id"];
string name = Request.QueryString["name"];
// Passing Query String
Response.Redirect("Profile.aspx?id=" + txtID.Text + "&name=" + txtName.Text);
URL Encoding
Used to encode special characters in data so they can be safely transmitted through a URL. ASP.NET provides Server.UrlEncode().
Response.Redirect("Profile.aspx?id=" + txtID.Text +
"&name=" + Server.UrlEncode(txtName.Text));
If txtName = Riya Sharma, the URL becomes ...name=Riya%20Sharma.
Advantages & Limitations
- 1 Simple to use.
- 2 Useful for page-to-page communication.
- 3 Easy to retrieve.
- 4 Bookmarkable.
- 1 Visible to the user in address bar.
- 2 Not suitable for sensitive data.
- 3 Limited size (~2000 chars).
- 4 Special characters require encoding.
Explain Session State Management with Example. Differentiate Session, Application and Cookies.
Session State is a server-side state management technique used to store user-specific data on the server and maintain it between different pages during a user's visit. Since HTTP is stateless, Session helps ASP.NET remember information between requests.
Each user gets a unique Session ID, and the default Session timeout is 20 minutes of inactivity.
Example
// Storing a value
Session["UserName"] = txtName.Text;
// Retrieving
if (Session["UserName"] != null) {
lblUser.Text = Session["UserName"].ToString();
}
// Removing
Session.Remove("UserName"); // Remove one value
Session.Clear(); // Clear all values
Session.Abandon(); // End the session
Session Modes
Difference between Session, Application and Cookies
| Feature | Session | Application | Cookies |
|---|---|---|---|
| Storage | Server | Server | Client browser |
| Scope | Per user | All users | Per user |
| Purpose | User-specific data | Application-wide data | Small user information |
| Timeout | Default ~20 minutes | Application lifetime | Configurable |
| Size | Can store .NET objects | Can store application data | About 4 KB |
| Security | Suitable for sensitive data | Suitable for shared server data | Not suitable for sensitive data |
Application → Server-side, all users
Cookie → Client-side, one user
Explain ASP.NET State Management Techniques.
State Management is the technique of maintaining data between different requests and pages in an ASP.NET application. This is necessary because HTTP is stateless.
1. Client-Side State Management
Data is maintained on the client/browser.
2. Server-Side State Management
Data is maintained on the web server.
Comparison
| Technique | Storage | Scope | Main Use |
|---|---|---|---|
| ViewState | Client (hidden field) | Current page | Maintain control values |
| Cookies | Client browser | Per user | Small user information |
| Query String | URL | Per request | Pass parameters between pages |
| Session | Server | Per user | Login, cart, preferences |
| Application | Server | All users | Application-wide data |
Explain Web Services, Features, and Advantages. Describe SOAP and WSDL.
A Web Service is a software component accessible over a network that allows different applications to communicate and exchange information using standard protocols. In classic ASP.NET, they use the .asmx extension and expose methods via the [WebMethod] attribute.
Features and Advantages
- 01Platform Independent: Applications on different platforms can communicate.
- 02Language Independent: Client and Service can be in different languages.
- 03Interoperability: Uses standard technologies like HTTP, XML, SOAP.
- 04Reusable: Single service used by multiple applications.
- 05Loosely Coupled: Client only needs to know the service operation/parameters, not internal implementations.
SOAP and WSDL
| SOAP | WSDL |
|---|---|
| Simple Object Access Protocol | Web Services Description Language |
| Used for message communication. | Used to describe the Web Service. |
| Defines request/response message format. | Describes operations, parameters and return values. |
| XML-based messaging protocol. | XML-based service description document. |
| How messages are exchanged. | What the service provides. |
Explain the Steps to Create and Consume an ASMX Web Service.
An ASMX Web Service is a classic ASP.NET Web Service that uses the .asmx extension.
A. Steps to Create an ASMX Web Service
- Step 1 Create a new ASP.NET Web Application (.NET Framework).
- Step 2 Add New Item → Select Web Service (ASMX) (e.g.,
StudentService.asmx). - Step 3 Write the Web Service code in the
.csfile using the[WebMethod]attribute. - Step 4 Run and Test the service in the browser.
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
B. Steps to Consume the ASMX Web Service
Consuming means using the Web Service from a client application.
- Step 1 Obtain the Web Service URL.
- Step 2 In the client app, add a Web Reference / Service Reference using the URL.
- Step 3 A Proxy Class is automatically generated from the WSDL.
- Step 4 Create a Proxy Object and call the Web Service Method.
StudentWS.StudentService svc = new StudentWS.StudentService();
int result = svc.Add(10, 20);
lblResult.Text = result.ToString();
C. Overall Communication Flow
Create ASMX Service
↓
Write [WebMethod]
↓
Run & Test Service
↓
Get WSDL
↓
Add Web Reference
↓
Proxy Class Generated
↓
Client Calls Method
↓
SOAP Request
↓
Web Service Executes
↓
SOAP Response
↓
Client Receives Result