You are a web developer for a company named XYZ. Your ASP.NET application needs to connect by using Windows Integrated authentication to the FactoryDB database in a SQL Server 2000 named instance called Factory on server XYZ01. Which SqlConnection connection string should you use?

Difficulty: Medium

Correct Answer: Data Source=XYZ01\\Factory;Database=FactoryDB;Integrated Security=SSPI;

Explanation:


Introduction / Context:
ASP.NET applications typically connect to Microsoft SQL Server databases by using connection strings in web.config or directly in code. When a database is hosted in a named instance rather than the default instance, the connection string must explicitly specify the server name and instance name together. Additionally, when security requirements call for Windows Integrated authentication, the Integrated Security keyword must be correctly configured. This question focuses on composing a correct connection string that points to a specific database in a named instance.


Given Data / Assumptions:

    The SQL Server 2000 machine is named XYZ01.
    There is a named instance of SQL Server on XYZ01 called Factory.
    The database to connect to is named FactoryDB, hosted in the Factory instance.
    The ASP.NET application must use Windows Integrated authentication, not a SQL Server login.
    The connection is created with a SqlConnection object, so the standard SQL Server connection string syntax applies.


Concept / Approach:
To connect to a named instance of SQL Server, you specify the Data Source (or Server) as serverName\\instanceName, using a double backslash in C sharp string literals and a single backslash in the connection string value. You then specify the database either with Database or Initial Catalog, which are synonyms. For Windows Integrated authentication, you use Integrated Security=SSPI; on Windows. The connection string must therefore include three key elements: the correct server and instance name, the correct database name, and Integrated Security=SSPI.


Step-by-Step Solution:
1. Identify the correct server and instance part. Because the instance name is Factory on server XYZ01, the Data Source should be XYZ01\\Factory. 2. Identify the database name. The question states that the application must use FactoryDB, so the connection string must specify Database=FactoryDB or Initial Catalog=FactoryDB. 3. Identify the authentication method. You are required to use Windows Integrated authentication, which means the connection string should include Integrated Security=SSPI; to use the application pool identity or the current Windows identity. 4. Combine these elements, resulting in a format similar to Data Source=XYZ01\\Factory;Database=FactoryDB;Integrated Security=SSPI; which points to the named instance and database and uses integrated security. 5. Compare this with the options and choose the one that exactly matches these requirements.


Verification / Alternative check:
You can verify this pattern by checking Microsoft documentation for connection strings to named instances or by testing the connection string in a small console application. Successful connection without prompting for credentials, and correct retrieval of data from FactoryDB, confirm that the connection string is correctly formed.


Why Other Options Are Wrong:
Options that specify Data Source=Factory or Server=XYZ01;Data Source=Factory do not correctly combine the server name and instance name into one logical Data Source value, so they may not resolve to the correct server instance.
Options that use Initial Catalog=Factory instead of FactoryDB refer to the instance name as the database name, which is incorrect for this scenario.
Any option that misconfigures Integrated Security or omits it would not satisfy the requirement to use Windows Integrated authentication.


Common Pitfalls:
Developers sometimes confuse the SQL Server instance name with the database name, resulting in connection strings that point to the wrong target. Another common mistake is forgetting to include the backslash between the server name and the instance name. It is also easy to mix SQL authentication and Windows authentication keywords, which can cause authentication failures. Always verify server name, instance name, database name, and authentication settings together when forming a connection string.


Final Answer:
The correct connection string is Data Source=XYZ01\\Factory;Database=FactoryDB;Integrated Security=SSPI;.

More Questions from Microsoft Certification

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion