--- title: "Developing a User Interface for a Custom Connection Manager | Microsoft Docs" ms.custom: "" ms.date: "03/06/2017" ms.prod: sql ms.prod_service: "integration-services" ms.reviewer: "" ms.technology: integration-services ms.topic: "reference" helpviewer_keywords: - "custom connection managers [Integration Services], developing user interface" - "custom user interface [Integration Services], custom connection manager" ms.assetid: 908bf2ac-fc84-4af8-a869-1cb43573d2df author: chugugrace ms.author: chugu --- # Developing a User Interface for a Custom Connection Manager [!INCLUDE[ssis-appliesto](../../../includes/ssis-appliesto-ssvrpluslinux-asdb-asdw-xxx.md)] 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 , and the Windows form that it displays to gather information from the user. > [!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](../../../integration-services/extending-packages-custom-objects/building-deploying-and-debugging-custom-objects.md), remember to provide the fully qualified name of this class in the property of the . > [!NOTE] > Most of the tasks, sources, and destinations that have been built into [!INCLUDE[ssISnoversion](../../../includes/ssisnoversion-md.md)] work only with specific types of built-in connection managers. Therefore, these samples cannot be tested with the built-in tasks and components. ## Coding the User Interface Class The interface has four methods: , , , and . The following sections describe these four methods. > [!NOTE] > You may not need to write any code for the method if no cleanup is required when the user deletes an instance of the connection manager. ### Initializing the User Interface In the 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 managerfor later use. ```vb Public Sub Initialize(ByVal connectionManager As Microsoft.SqlServer.Dts.Runtime.ConnectionManager, ByVal serviceProvider As System.IServiceProvider) Implements Microsoft.SqlServer.Dts.Runtime.Design.IDtsConnectionManagerUI.Initialize _connectionManager = connectionManager _serviceProvider = serviceProvider End Sub ``` ```csharp 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 method, which is not a constructor, is called after the method when the user creates a new instance of the connection manager. In the 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. ```vb Public Function [New](ByVal parentWindow As System.Windows.Forms.IWin32Window, ByVal connections As Microsoft.SqlServer.Dts.Runtime.Connections, ByVal connectionUIArgs As Microsoft.SqlServer.Dts.Runtime.Design.ConnectionManagerUIArgs) As Boolean Implements Microsoft.SqlServer.Dts.Runtime.Design.IDtsConnectionManagerUI.New Dim clipboardService As IDtsClipboardService clipboardService = _ DirectCast(_serviceProvider.GetService(GetType(IDtsClipboardService)), IDtsClipboardService) If Not clipboardService Is Nothing Then ' If the connection manager has been copied and pasted, take no action. If clipboardService.IsPasteActive Then Return True End If End If Return EditSqlConnection(parentWindow) End Function ``` ```csharp 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 and the 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. ```vb Private Function EditSqlConnection(ByVal parentWindow As IWin32Window) As Boolean Dim sqlCMUIForm As New SqlConnMgrUIFormVB sqlCMUIForm.Initialize(_connectionManager, _serviceProvider) If sqlCMUIForm.ShowDialog(parentWindow) = DialogResult.OK Then Return True Else Return False End If End Function ``` ```csharp 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 method, you simply have to display the form for editing. The following code shows an implementation of the method that uses a helper function to encapsulate the code for the form. ```vb Public Function Edit(ByVal parentWindow As System.Windows.Forms.IWin32Window, ByVal connections As Microsoft.SqlServer.Dts.Runtime.Connections, ByVal connectionUIArg As Microsoft.SqlServer.Dts.Runtime.Design.ConnectionManagerUIArgs) As Boolean Implements Microsoft.SqlServer.Dts.Runtime.Design.IDtsConnectionManagerUI.Edit Return EditSqlConnection(parentWindow) End Function ``` ```csharp public bool Edit(System.Windows.Forms.IWin32Window parentWindow, Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.Design.ConnectionManagerUIArgs connectionUIArg) { return EditSqlConnection(parentWindow); } ``` ## Coding the User Interface Form After creating the user interface class that implements the methods of the 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. ```vb Public Sub Initialize(ByVal connectionManager As ConnectionManager, ByVal serviceProvider As IServiceProvider) _connectionManager = connectionManager _serviceProvider = serviceProvider ConfigureControlsFromConnectionManager() EnableControls() End Sub ``` ```csharp 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. ```vb Private Const CONNECTIONNAME_BASE As String = "SqlConnectionManager" Private Sub ConfigureControlsFromConnectionManager() Dim tempName As String Dim tempServerName As String Dim tempDatabaseName As String With _connectionManager tempName = .Properties("Name").GetValue(_connectionManager).ToString If Not String.IsNullOrEmpty(tempName) Then _connectionName = tempName Else _connectionName = CONNECTIONNAME_BASE End If tempServerName = .Properties("ServerName").GetValue(_connectionManager).ToString If Not String.IsNullOrEmpty(tempServerName) Then _serverName = tempServerName txtServerName.Text = _serverName End If tempDatabaseName = .Properties("DatabaseName").GetValue(_connectionManager).ToString If Not String.IsNullOrEmpty(tempDatabaseName) Then _databaseName = tempDatabaseName txtDatabaseName.Text = _databaseName End If End With End Sub Private Sub ConfigureConnectionManagerFromControls() With _connectionManager .Properties("Name").SetValue(_connectionManager, _connectionName) .Properties("ServerName").SetValue(_connectionManager, _serverName) .Properties("DatabaseName").SetValue(_connectionManager, _databaseName) End With End Sub ``` ```csharp 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); } } ``` ## See Also [Creating a Custom Connection Manager](../../../integration-services/extending-packages-custom-objects/connection-manager/creating-a-custom-connection-manager.md) [Coding a Custom Connection Manager](../../../integration-services/extending-packages-custom-objects/connection-manager/coding-a-custom-connection-manager.md)