Microsoft TS: Accessing Data with Microsoft .NET Framework 4 Sample Questions:
1. You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL Server
2008 database.
The database contains a ClassStudent table that contains the StudentID for students who are enrolled in
the classes.
You add the following stored procedure to the database.
CREATE PROCEDURE [dbo].[GetNumEnrolled] @ClassID INT, @NumEnrolled INT OUTPUT
AS BEGIN SET NOCOUNT ON SELECT @NumEnrolled = COUNT(StudentID)
FROM ClassStudent
WHERE (ClassID = @ClassID)
END
You write the following code. (Line numbers are included for reference only.)
01 private int GetNumberEnrolled(string classID)
02 {
03 using (SqlConnection conn = new SqlConnection(GetConnectionString())
04 {
05 SqlCommand cmd = new SqlCommand("GetNumEnrolled", conn);
06 cmd.CommandType = CommandType.StoredProcedure;
07 SqlParameter parClass = cmd.Parameters.Add("@ClassID", SqlDbType.Int,
4, "classID");
08 SqlParameter parNum = cmd.Parameters.Add("@NumEnrolled",
SqlDbType.Int);
09 ...
10 conn.Open()
11 ...
12 }
13 }
You need to ensure that the GetNumberEnrolled method returns the number of students who are enrolled
for a specific class.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A) Insert the following code at line 11.
int numEnrolled = 0;
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
numEnrolled = numEnrolled + (int)cmd.Parameters["@NumEnrolled"].Value; } return numEnrolled;
B) Insert the following code at line 09.
parNum.Direction = ParameterDirection.Input;
C) Insert the following code at line 09.
parNum.Direction = ParameterDirection.Output;
D) Insert the following code at line 11.
cmd.ExecuteNonQuery();
return (int)parNum.Value;
2. You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create a Windows Forms
application.
You plan to deploy the application to several shared client computers. You write the following code
segment.
(Line numbers are included for reference only.)
01 Configuration config = ConfigurationManager.OpenExeConfiguration
(exeConfigName);
02 ...
03 config.Save();
04 ...
You need to encrypt the connection string stored in the .config file. Which code segment should you insert at line 02?
A) ConnectionStringsSection section = config.GetSection("connectionString") as ConnectionStringsSection; section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
B) ConnectionStringsSection section = config.GetSection("connectionString") as ConnectionStringsSection; section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
C) ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection; section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
D) ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection; section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
3. You use Microsoft Visual Studio 2010 and Microsoft. NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. You use Entity SQL of the ADO.NET Entity
Framework to retrieve data from the database.
You need to define a custom function in the conceptual model. You also need to ensure that the function
calculates a value based on properties of the object.
Which two XML element types should you use? (Each correct answer presents part of the solution. Choose
two.)
A) Function
B) FunctionImport
C) DefiningExpression
D) Dependent
E) Association
4. You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. You load records from the Customers table
into a DataSet object named dataset.
You need to retrieve the value of the City field from the first and last records in the Customers table.
Which code segment should you use?
A) DataTable dt = dataset.Tables["Customers"]; string first = dt.Rows[0]["City"].ToString(); string last = dt.Rows[dt.Rows.Count]["City"].ToString();
B) DataRelation relationFirst = dataset.Relations[0]; DataRelation relationLast = dataset.Relations[dataset.Relations.Count - 1]; string first = relationFirst.childTable.Columns["City"].ToString(); string last = relationLast.childTable.Columns["City"].ToString();
C) DataRelation relationFirst = dataset.Relations[0]; DataRelation relationLast = dataset.Relations[dataset.Relations.Count]; string first = relationFirst.childTable.Columns["City"].ToString(); string last = relationLast.childTable.Columns["City"].ToString();
D) DataTable dt = dataset.Tables["Customers"]; string first = dt.Rows[0]["City"].ToString(); string last = dt.Rows[dt.Rows.Count - 1]["City"].ToString();
5. You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server 2008 database. You add the following store procedure
to the database.
CREATE PROCEDURE GetSalesPeople AS BEGIN
SELECT FirstName, LastName, Suffix, Email, Phone FROM SalesPeople END
You write the following code segment. (Line numbers are included for reference only.)
01 SqlConnection connection = new SqlConnection("...");
02 SqlCommand command = new SqlCommand("GetSalesPeople", connection);
03 command.CommandType = CommandType.StoredProcedure;
04 ...
You need to retreive all of the results from the stored procedure. Which code segment should you insert at line 04?
A) var res = command.ExecuteNonQuery();
B) var res = command.ExecuteReader();
C) var res = command.ExecuteXmlReader();
D) var res = command.ExecuteScalar();
Solutions:
Question # 1 Answer: C,D | Question # 2 Answer: D | Question # 3 Answer: A,C | Question # 4 Answer: D | Question # 5 Answer: B |