private void SetConnectionString(object sender, EventArgs e)
 {
     if (!_loading)
     {
         string pwd = (Properties.Contains("pwd")) ? Properties["pwd"] as string : null;
         try
         {
             Properties.Parse(connectionStringTextBox.Text.Trim());
         }
         catch (ArgumentException ex)
         {
             IUIService uiService = null;
             if (ParentForm != null && ParentForm.Site != null)
             {
                 uiService = ParentForm.Site.GetService(typeof(IUIService)) as IUIService;
             }
             if (uiService != null)
             {
                 uiService.ShowError(ex);
             }
             else
             {
                 RTLAwareMessageBox.Show(null, ex.Message, MessageBoxIcon.Exclamation);
             }
         }
         if (connectionStringTextBox.Text.Trim().Length > 0 &&
             !Properties.Contains("pwd") && pwd != null)
         {
             Properties["pwd"] = pwd;
         }
         connectionStringTextBox.Text = Properties.ToDisplayString();
     }
     UpdateControls();
 }
        private void ShowDataLinks(object sender, EventArgs e)
        {
            try
            {
                // Create data links object as IDataInitialize
                Type dataLinksType = Type.GetTypeFromCLSID(NativeMethods.CLSID_DataLinks);
                NativeMethods.IDataInitialize dataInitialize = Activator.CreateInstance(dataLinksType) as NativeMethods.IDataInitialize;

                // Create data source object from connection string
                object dataSource = null;
                dataInitialize.GetDataSource(null,
                                             NativeMethods.CLSCTX_INPROC_SERVER,
                                             Properties.ToFullString(),
                                             ref NativeMethods.IID_IUnknown,
                                             ref dataSource);

                // Get IDBPromptInitialize interface from data links object
                NativeMethods.IDBPromptInitialize promptInitialize = (NativeMethods.IDBPromptInitialize)dataInitialize;

                // Display the data links dialog using this data source
                promptInitialize.PromptDataSource(
                    null,
                    ParentForm.Handle,
                    NativeMethods.DBPROMPTOPTIONS_PROPERTYSHEET | NativeMethods.DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION,
                    0,
                    IntPtr.Zero,
                    null,
                    ref NativeMethods.IID_IUnknown,
                    ref dataSource);

                // Retrieve the new connection string from the data source
                string newConnectionString = null;
                dataInitialize.GetInitializationString(dataSource, true, out newConnectionString);

                // Parse the new connection string into the connection properties object
                Properties.Parse(newConnectionString);

                // Reload the control with the modified connection properties
                LoadProperties();
            }
            catch (Exception ex)
            {
                COMException comex = ex as COMException;
                if (comex == null || comex.ErrorCode != NativeMethods.DB_E_CANCELED)
                {
                    IUIService uiService = this.GetService(typeof(IUIService)) as IUIService;
                    if (uiService != null)
                    {
                        uiService.ShowError(ex);
                    }
                    else
                    {
                        RTLAwareMessageBox.Show(null, ex.Message, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }