Variations on a Theme
The Credential Mode choices in Figure 1
, as stated earlier, manipulate the access level of the set of input fields via properties exposed by the ConnectionStringManager control. Table 2 shows how each credential mode renders.
Table 2. Setting Credential Modes: The table shows the effect of the various Credential Mode settings on the sub-controls in the ConnectionStringManager control.
||Here, the access level of all six input fields (username, password, server, DB type, database, and authentication) is set to Edit, allowing users to manipulate all the values.
|Name and Password
||Here, the server, DB type, and database are hidden from users—either because they're hard-coded and never need to be changed, or perhaps because the users don't have the requisite privileges to grant exposure.
|Server and DB
||You might use this scenario when your application uses a hard-coded "database user" account (where your application always uses a specific name and password) and you don't want to reveal those to users for security reasons.
||This scenario allows only the selection of a server by setting the access level of all other input fields to Hide.
When building your applications, you would typically decide on just one such configuration and set the properties of the ConnectionStringManager accordingly. Note how (by judicious use of the AutoSize
properties of both the control and the form) the credential form resizes intelligently depending on what is visible.
|Figure 4. The Server Choice List: Providing a set of values in the Server Choice List causes the server input field to render as a ComboBox; with no supplied values it renders as a TextBox.|
The ServerChoice list on the main form of the demo application provides one last setting that influences how the ConnectionStringManager renders. To restrict the available servers to a small, finite set (by far the most common case), supply the list of servers in the ServerChoice list (see Figure 4
, left side). On the credential form the list renders as a non-editable ComboBox, limiting users to selecting only one of your supplied choices. If you do not provide a list of servers, the control will instead be rendered as a TextBox that allows users to enter an arbitrary server name (see Figure 4
, right side).
As the demo application
shows, designers can configure the ConnectionStringManager control to alter the control's visual representation. But in some situations, the control's configuration can also change based on users' selections. The next sections illustrate this.
Windows Authentication and SQL Server Authentication
With SQL Server 2000 or 2005, you have the choice of allowing either Windows authentication or SQL Server authentication. Microsoft recommends using Windows authentication whenever possible . Windows authentication validates the user's currently logged on Windows account to determine whether the user has access to the given database. SQL Server authentication, on the other hand, uses the account registry contained within SQL Server itself. So if a user selects Windows authentication, they don't need to provide a name and password. As Figure 5 illustrates, the username and password fields become disabled when a user selects Windows authentication.
SQL Server vs. Oracle Database Types
|Figure 5. User-Level Configuration Based on Authentication Mode: Switching between Windows and SQL Server (SqlServer) authentication modes disables or enables the username and password fields.||
|Figure 6. User-Level Configuration Based on Database System: Switching between Oracle and SQL Server database types disables or enables the database field.||
The ConnectionStringManager can handle credentials for both SQL Server and Oracle, but the connection strings accepted by the two database systems each require different components. SQL Server has the concept of one server exposing many separate databases, while Oracle does not. Therefore, selecting Oracle disables the database ComboBox while selecting SQL Server enables it (see Figure 6