Working with ADO.NET - More questions

Working with ADO.NET - More questions


1. What is Multiple Active Result Sets (MARS)?

A) It allows execution of multiple batches against Database on a single connection.
B) New feature of SQL SERVER 2005. Previous version of SQL Server does not support this feature.
C) Option A and B are correct.
D) None of the above.

View Answer / Hide Answer

ANSWER: C




2. MARS feature is disabled by default. What action you will perform in connection string to enable this feature?

A) Set MultipleActiveResultSets=True"
B) Set MultipleResultSets=true"
C) Set ResultSets=True"
D) None of the above.

View Answer / Hide Answer

ANSWER: A

Explanation:

MARS is disabled by default on the Connection object. You have to enable it with the addition of MultipleActiveResultSets=true in your connection string.

using System.Data;
using System.Data.SqlClient;

SqlConnection conn = new SqlConnection(@"Data Source=ServerName;
Initial Catalog=DataBaseName;Integrated Security=SSPI;MultipleActiveResultSets=true;");
string SQL1="select * from Salary;";
string SQL2="select * from Employees;";

SqlCommand cmd1 = new SqlCommand(SQL1, con);
SqlCommand cmd2 = new SqlCommand(SQL2, con);
SqlDataReader rdr1 = null;
SqlDataReader rdr2 = null;
try
{
con.Open();
rdr1=cmd1.ExecuteReader();
rdr2=cmd2.ExecuteReader();

// you can write code here to retrieve the data from rdr1 and rdr2.
}
catch (SqlException ex)
{ }
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}




3. Choose the correct option about DataReader object.

A) DataReader object is a forward-only object.
B) It provides connection oriented environment.
C) DataReader is read only object.
D) All of the above

View Answer / Hide Answer

ANSWER: D




4. Choose the correct option about DataSet object.

A) Provides Disconnected mode
B) Can store multiple table simultaneously
C) Consumer Object
D) All of the above.

View Answer / Hide Answer

ANSWER: D




5. What is the difference between a local transaction and a distributed transaction?

A) Local transactions are performed on a single database table, but distributed transactions are performed on more than one database tables.
B) Local transactions are performed on a single database server, but distributed transactions can be performed across multiple database servers.
C) Local transactions are performed on a database on the local machine, but distributed transactions are performed on a database on a remote machine.
D) None of the above.

View Answer / Hide Answer

ANSWER: B




6. What are the three main objects when working with a DataSet?

A) DataTable, DataColumn, and type.
B) DataTable, DataRelation, and DataAdapter.
C) DataTable, DataColumn, and DataRelation.
D) DataReader,DataAdapter, and Command.

View Answer / Hide Answer

ANSWER: C




7. What are the steps to create a DataTable programmatically?

A) Instantiate a new DataTable and add DataColumn objects to the DataTable.Columns collection.
B) Run the Data Source Configuration Wizard.
C) Instantiate a new DataSet object.
D) None of the above.

View Answer / Hide Answer

ANSWER: A

Explanation:

using System;
using System.Data;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable("Employee"); // Create the table object
DataColumn dc = new DataColumn();
DataRow dr;
dc.ColumnName = "ID"; //Heading of the column
dc.DataType = Type.GetType("System.Int32"); //Set the type of ID as Integer
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "ItemName";
dc.DataType = Type.GetType("System.String"); //Set the type of ItemName as String
dt.Columns.Add(dc);


for (int i = 0; i <= 4; i++)
{
dr = dt.NewRow();
dr["id"] = i; //This for loop will create 5 new rows
and add to the table.
dr["ItemName"] = "Item " + i;
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}




8. On what object would you set the properties to create a primary key for a DataTable?

A) DataRelation
B) DataColumn
C) DataSet
D) DataTable

View Answer / Hide Answer

ANSWER: C




9. Which Data Provider gives the maximum performance when connect to SQL Server?

A) The SqlClient data provider.
B) The OLE DB data provider.
C) The Oracle data provider
D) All of the above.

View Answer / Hide Answer

ANSWER: A




10. What are the three primary kinds of parameter when working with stored procedure in ASP.NET

A) Input, Integer, String
B) int, varchar, nvarchar
C) Input, Output, InputOutput
D) All of the above.

View Answer / Hide Answer

ANSWER: C




11. The three statements are given below about DataSet and DataReader, choose the correct option according to the statement.
Statement 1: DataSet Provides Disconnected environment but DataReader provides Connected environment.
Statement 2: DataSet Provides Connected environment but DataReader provides Disconnected environment.
Statement 3: DataSet Can store multiple table simultaneously but DataReader Supports a single table based on a single SQL query.

A) Only Statement 1 is correct.
B) Statement 1 and 2 is correct.
C) Statement 2 and 3 is correct.
D) Statement 1 and 3 is correct.

View Answer / Hide Answer

ANSWER: D




12. You want to secure the connection strings contained within your Web.config file to ensure that no one can open the file easily and see the connection information. Which
tool must you use to encrypt the connection strings?

A) ASPNET_WP.EXE
B) ASPNET_REGSQL.EXE
C) ASPNET_REGIIS.EXE.
D) None of the above.

View Answer / Hide Answer

ANSWER: C

Explanation:

When working with Web applications, you can encrypt the connection strings stored in the Web.config file by using the ASPNET_REGIIS.EXE tool.
ASPNET_REGSQL.EXE is used to configure SQL server.




13. In which file you should write the connection string, so you can access it in all the web page for same application?

A) In App_Data folder.
B) In Web.config file.
C) In MasterPage file.
D) None of the above.

View Answer / Hide Answer

ANSWER: B

Explanation:

Following are the steps to create the connection string in Web.config file and access it in code behind file. In connection string data source and database name you have to provide according to your sqlserver instance and their database name.
Step 1: Create the connection string in Web.config file as follows.
<connectionStrings>
<add name="con" connectionString="Data Source =ServerName; initial catalog= DataBaseName; Integrated Security=true"/>
</connectionStrings>


Step 2: In code behind file write the following code.
ConfigurationManager class is available in System.Configuration namespace;

string conStr= ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection conObj = new SqlConnection(conStr);
conObj.Open();

// Write code according to the requirement.

conObj.Close();




Post your comment