PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft .NET Framework 4.0 to develop an ASP.NET Web application that connects to a Microsoft SQL Server 2008 database.
The application uses Integrated Windows authentication in Internet Information Services (IIS) to authenticate users.
A connection string named connString defines a connection to the database by using integrated security.

You need to ensure that a SqlCommand executes under the application pool’s identity on the database server.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
using (var conn = new SqlConnection())
{
conn.ConnectionString = connString;
SqlCommand cmd = null;
using (HostingEnvironment.Impersonate())
{
cmd = new SqlCommand(“SELECT * FROM BLOG”, conn);
}
conn.Open();
var result = cmd.ExecuteScalar();
}

B.
using (var conn = new SqlConnection(connString))
{
var cmd = new SqlCommand (“SELECT * FROM BLOG, conn);
conn.Open();
using(HostingEnvironment.Impersonate())
{
var result = cmd.ExecuteScalar();
}
}

C.
using (var conn = new SqlConneccion())
{
using (HostingEnvironroent.Impersonate())
{
conn.ConnectionString = connString;
}
var cmd = new SqlCommand(“SELECT * FROM BLOG, conn);
conn.Open() ;
var result = cmd.ExecuteScalar();
}

D.
using (var conn = new SqlConnection())
{
conn.ConnectionString = connString;
var cmd = new SqlCommand(“SELECT * FROM BLOG”, conn);
using (HostingEnvironment.Impersonate())
{
conn.Open();
}
var result = cmd.ExecuteScalar();
}

3 Comments on “Which code segment should you use?


Leave a Reply