You use Microsoft .NET Framework 4.0 to develop an ASP.NET application. The application uses Integrated Windows authentication.
The application accesses data in a Microsoft SQL Server 2008 database that is located on the same server as the application.
You use the following connection string to connect to the database.
Integrated Security=SSPI; Initial Catalog=AdventureWorks;
The application must also execute a stored procedure on the same server on a database named pubs.
Users connect to the ASP.NET application through the intranet by using Windows-based authentication.
You need to ensure that the application will use connection pooling whenever possible and will keep the number of pools to a minimum.
Which code segment should you use?
A.
command.CommandText = “USE [pubs]; exec uspLoginAudit;”;
using (SqlConnection connection = new SqlConnection( “Initial Catalog=AdventureWorks; Integrated Security=SSPI; MultipleActiveResultSets=True”)) {
connection.Open();
command.ExecuteNonQuery();
}
B.
command.CommandText = “exec uspLoginAudit;”;
using (SqlConnection connection = new SqlConnection( “Integrated Security=SSPI;”)) {
connection.Open();
command.ExecuteNonQuery();
}
C.
command.CommandText = “USE [pubs]; exec uspLoginAudit;”;
using (SqlConnection connection = new SqlConnection( “Integrated Security=SSPI; Initial Catalog=AdventureWorks”)) {
connection.Open();
command.ExecuteNonQuery();
}
D.
command.CommandText = “exec uspLoginAudit;”;
using (SqlConnection connection = new SqlConnection( “Integrated Security=SSPI; Initial Catalog=pubs”)) {
connection.Open();
command.ExecuteNonQuery();
}
Explanation:
Working with Multiple Active Result Sets
(http://msdn.microsoft.com/en-us/library/yf1a7f4f(v=vs.80).aspx)SSPI
(http://msdn.microsoft.com/en-us/library/windows/desktop/aa380493(v=vs.85).aspx)
A is correct answer
MARS allows a connection to be used for both read operations and data manipulation language (DML) operations with more than one pending operation. This feature eliminates the need for an application to deal with connection-busy errors. In addition, MARS can replace the user of server-side cursors, which generally consume more resources. Finally, because multiple operations can operate on a single connection, they can share the same transaction context, eliminating the need to use sp_getbindtoken and sp_bindsession system stored procedures.
A is not correct, because, in order to ensure the connection joins the same connection pool as the rest of the app, the connection string must be identical to the connection string used elsewhere in the app. MARS, by contrast, will let you share a connection between commands, but has nothing to do with connection pool assignment for that connection.
Agreed with Gaius. The answer is C and not A. Here’s why:
http://msdn.microsoft.com/en-us/library/h32h3abf%28v=vs.110%29.aspx
“MARS-enabled connections are pooled like any other connection. If an application opens two connections, one with MARS enabled and one with MARS disabled, the two connections are in separate pools.”
So you’ll end up with two separate pools if you select answer A. Not what the question wants.