Export (0) Print
Expand All

Developing a User Interface for a Custom Connection Manager

After you have overridden the implementation of the properties and methods of the base class to provide your custom functionality, you may want to create a custom user interface for your connection manager. If you do not create a custom user interface, users can configure your connection manager only by using the Properties window.

In a custom user interface project or assembly, you normally have two classes—a class that implements IDtsConnectionManagerUI, and the Windows form that it displays to gather information from the user.

Important note Important

After signing and building your custom user interface and installing it in the global assembly cache as described in Coding a Custom Connection Manager, remember to provide the fully qualified name of this class in the UITypeName property of the DtsConnectionAttribute.

Note Note

Most of the tasks, sources, and destinations that have been built into Integration Services work only with specific types of built-in connection managers. Therefore, these samples cannot be tested with the built-in tasks and components.

The IDtsConnectionManagerUI interface has four methods: Initialize, New, Edit, and Delete. The following sections describe these four methods.

Note Note

You may not need to write any code for the Delete method if no cleanup is required when the user deletes an instance of the connection manager.

Initializing the User Interface

In the Initialize method, the designer provides a reference to the connection manager that is being configured so that the user interface class can modify the connection manager's properties. As shown in the following code, your code needs to cache the reference to the connection manager for later use.

    public void Initialize(Microsoft.SqlServer.Dts.Runtime.ConnectionManager connectionManager, System.IServiceProvider serviceProvider)
    {

      _connectionManager = connectionManager;
      _serviceProvider = serviceProvider;

    }

Creating a New Instance of the User Interface

The New method, which is not a constructor, is called after the Initialize method when the user creates a new instance of the connection manager. In the New method, you usually want to display the form for editing, unless the user has copied and pasted an existing connection manager. The following code shows an implementation of this method.

  public bool New(System.Windows.Forms.IWin32Window parentWindow, Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.Design.ConnectionManagerUIArgs connectionUIArgs)
    {
      IDtsClipboardService clipboardService;

      clipboardService = (IDtsClipboardService)_serviceProvider.GetService(typeof(IDtsClipboardService));
      if (clipboardService != null)
      // If connection manager has been copied and pasted, take no action.
      {
        if (clipboardService.IsPasteActive)
        {
          return true;
        }
      }

      return EditSqlConnection(parentWindow);
    }

Editing the Connection Manager

Because the form for editing is called from both the New and the Edit methods, it is convenient to use a helper function to encapsulate the code that displays the form. The following code shows an implementation of this helper function.

   private bool EditSqlConnection(IWin32Window parentWindow)
    {

      SqlConnMgrUIFormCS sqlCMUIForm = new SqlConnMgrUIFormCS();

      sqlCMUIForm.Initialize(_connectionManager, _serviceProvider);
      if (sqlCMUIForm.ShowDialog(parentWindow) == DialogResult.OK)
      {
        return true;
      }
      else
      {
        return false;
      }

    }

In the Edit method, you simply have to display the form for editing. The following code shows an implementation of the Edit method that uses a helper function to encapsulate the code for the form.

    public bool Edit(System.Windows.Forms.IWin32Window parentWindow, Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.Design.ConnectionManagerUIArgs connectionUIArg)
    {

      return EditSqlConnection(parentWindow);

    }

After creating the user interface class that implements the methods of the IDtsConnectionManagerUI interface, you must create a Windows form where the user can configure the properties of your connection manager.

Initializing the User Interface Form

When you display your custom form for editing, you can pass a reference to the connection manager that is being edited. You can pass this reference either by using a custom constructor for the form class, or by creating your own Initialize method as shown here.

   public void Initialize(ConnectionManager connectionManager, IServiceProvider serviceProvider)
    {

      _connectionManager = connectionManager;
      _serviceProvider = serviceProvider;
      ConfigureControlsFromConnectionManager();
      EnableControls();

    }

Setting Properties on the User Interface Form

Finally, your form class needs a helper function that populates the controls on the form when it is first loaded with the existing or the default values of the properties of the connection manager. Your form class also needs a similar function that sets the values of the properties to the values entered by the user when the user clicks OK and closes the form.

   private const string CONNECTIONNAME_BASE = "SqlConnectionManager";

   private void ConfigureControlsFromConnectionManager()
    {

      string tempName;
      string tempServerName;
      string tempDatabaseName;

      {
        tempName = _connectionManager.Properties["Name"].GetValue(_connectionManager).ToString();
        if (!String.IsNullOrEmpty(tempName))
        {
          _connectionName = tempName;
        }
        else
        {
          _connectionName = CONNECTIONNAME_BASE;
        }

        tempServerName = _connectionManager.Properties["ServerName"].GetValue(_connectionManager).ToString();
        if (!String.IsNullOrEmpty(tempServerName))
        {
          _serverName = tempServerName;
          txtServerName.Text = _serverName;
        }

        tempDatabaseName = _connectionManager.Properties["DatabaseName"].GetValue(_connectionManager).ToString();
        if (!String.IsNullOrEmpty(tempDatabaseName))
        {
          _databaseName = tempDatabaseName;
          txtDatabaseName.Text = _databaseName;
        }

      }

    }

    private void ConfigureConnectionManagerFromControls()
    {

      {
        _connectionManager.Properties["Name"].SetValue(_connectionManager, _connectionName);
        _connectionManager.Properties["ServerName"].SetValue(_connectionManager, _serverName);
        _connectionManager.Properties["DatabaseName"].SetValue(_connectionManager, _databaseName);
      }

    }
Integration Services icon (small) Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN:


For automatic notification of these updates, subscribe to the RSS feeds available on the page.

Community Additions

ADD
Show:
© 2014 Microsoft