RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


.NET Building Blocks: Build a Configurable Database Credential Selector : Page 2

This handy control gives you everything you need to control how users input usernames, passwords, select servers, and choose connection types.

First Look: The Configurator
The ConnectionStringManagerDemo sample project accompanying this article gives you a sandbox in which to explore the flexibility of the ConnectionStringManager control. Figure 1 shows the main form of the demo project.

The application includes a secondary form—the Credential Input Form (see Figure 2)—where the ConnectionStringManager control actually resides. This simple architecture mirrors a typical application; the main form does the real work, displaying the secondary login or credential form when appropriate. In this demo application, the Change button on the form in Figure 1 opens the Credential Input Form shown in Figure 2. The Current Credentials TextBox holds the connection string passed to the credential form. As you can see, the sample application is, in essence, a configurator; it lets a user interactively customize or configure the credential form.

Figure 1. ConnectionStringManager Demo: The main form provides controls so you can tailor the credential form at run time.
Figure 2. The Credential Input Form: This sub-form shows the ConnectionStringManager control with a variety of TextBox, ComboBox, RadioButton, CheckBox, Label, and Button controls.
Proceeding downward on the form in Figure 1, you'll see the Pending Credentials area, which displays the return values from the credential form—an output pane if you will. The Copy Back to Input button provides a convenient way to copy the output back to the input for continued experimentation. The Run Test Query button uses the connection string in the Current Credentials to invoke a simple query, just to let you test whether the supplied credentials are correct.

To use the Run Test Query button—and to be able to fully exercise the ConnectionStringManager—you will need to have at least one database available (preferably more than one). The starting connection string, shown in Figure 1, is typical for a local instance of SQL Server 2005 Express Edition.

Down the left side of the main form are input controls that let you configure the visual and behavioral characteristics of the ConnectionStringManager on the credential form. The Credential Mode section presents four common configurations of the input controls. Each radio button in this section represents a group of settings in the ConnectionStringManager.

The two choices in the Rendering section work in conjunction with the Credential Mode choice. Choosing a Credential Mode directs the ConnectionStringManager to allow users to interact with some fields and not with others. The ones in the latter category may either be hidden from view or disabled; the ConnectionStringManager employs three levels of access (see Table 1) that let you decide.

Table 1. Three Access Levels: You can display input controls as either enabled or disabled, or hide the controls.
Level Description Result
Edit Display the component and enable it Visible and Enabled
Display Display the component and disable it Visible and Disabled
Hide Do not display the component Not Visible

The rendering adjustment on the main form, therefore, selects between a disabled control (Display) and a hidden control (Hide). You'll find this feature particularly handy with nested access, discussed later.

The Accessories section of the form in Figure 1 contains several check boxes, which function as follows:

  • Expose Pwd Choice displays or hides a field on the form that lets users decide whether an application should remember their passwords. It is up to you to act on each user's choice; this option merely provides the user interface component.
  • Expose Status Text displays or hides a field that produces diagnostic output when the user tests the connection on the credential form.
  • Expose Test Button displays or hides a combination test button/status indicator. This button lets users check their entered credentials before leaving the credential form (making it quicker to correct a typographic error, for example). The button changes color depending on the state of the connection. When a connection error occurs, the button turns red and an ErrorProvider component becomes visible. Users may hover over the ErrorProvider with the mouse to see the error details. Those error details also appear in the result text box exposed by the previous check box.
The final configuration control on the left side of the main form is the Server Choice list. This field accepts a list of one or more servers that the ConnectionStringManager control will present to users in a ComboBox on the credential form, letting you limit users to a preloaded list of servers from which they can choose. If you do not provide a list of servers, then the control instead opts for a simple TextBox that allows users to enter an arbitrary server name.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date