public static string PromptEdit(string connectionString)
        {
            var inputConnection = new ConnectionClass();

            try
            {
                inputConnection.ConnectionString = connectionString;
                var dataLinks = new DataLinksClass();
                try
                {
                    object connectionRef = inputConnection;
                    if (dataLinks.PromptEdit(ref connectionRef))
                    {
                        _Connection outputConnection = (_Connection)connectionRef;
                        try
                        {
                            return(outputConnection.ConnectionString);
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(connectionRef);
                        }
                    }
                    return(null);
                }
                finally
                {
                    Marshal.ReleaseComObject(dataLinks);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(inputConnection);
            }
        }
Exemplo n.º 2
0
        private string GetConnectionString(string connectionString)
        {
            DataLinksClass dataLinks  = new DataLinksClass();
            _Connection    connection = null;

            if (String.IsNullOrEmpty(connectionString))
            {
                connection = dataLinks.PromptNew() as _Connection;
                if (connection == null)
                {
                    return("");
                }
                return(connection.ConnectionString);
            }

            connection = new ConnectionClass();
            connection.ConnectionString = connectionString;
            object objConnection = connection;

            if (dataLinks.PromptEdit(ref objConnection))
            {
                return(connection.ConnectionString);
            }
            return(connectionString);
        }
        public static string PromptNew()
        {
            var dataLinks = new DataLinksClass();

            try
            {
                var connection = dataLinks.PromptNew() as _Connection;
                if (connection != null)
                {
                    try
                    {
                        return(connection.ConnectionString);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(connection);
                    }
                }
                return(null);
            }
            finally
            {
                Marshal.ReleaseComObject(dataLinks);
            }
        }
Exemplo n.º 4
0
        private static bool GetModifiedConnectionStringFromWizard(string existingConnectionString, out string modifiedConnectionString)
        {
            modifiedConnectionString = null;

            try
            {
                DataLinks dataLinks = new DataLinksClass();

                ADODB.Connection connection = new ADODB.ConnectionClass {
                    ConnectionString = existingConnectionString
                };
                object refObject = connection;
                if (dataLinks.PromptEdit(ref refObject))
                {
                    modifiedConnectionString = connection.ConnectionString;
                    return(true);
                }

                return(false);
            }
            catch
            {
                string newConnectionString;
                if (GetNewConnectionStringFromWizard(out newConnectionString))
                {
                    modifiedConnectionString = newConnectionString;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 5
0
        public string EditValue(string value)
        {
            DataLinks dataLinks = new DataLinksClass();

            var con = (Connection)dataLinks.PromptNew();
            if (con == null)
                return value;
            return con.ConnectionString;
        }
Exemplo n.º 6
0
        public string EditValue(string value)
        {
            DataLinks dataLinks = new DataLinksClass();

            var con = (Connection)dataLinks.PromptNew();

            if (con == null)
            {
                return(value);
            }
            return(con.ConnectionString);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles event when Create Connection button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void CreateConnCommandClick(object param)
        {
            DataLinks udl = new DataLinksClass();

            udl.hWnd = _windowHandle != IntPtr.Zero ? _windowHandle.ToInt32() :
                       new WindowInteropHelper(App.Current.MainWindow).Handle.ToInt32();
            _connAdo = udl.PromptNew() as ADODB.Connection;

            if ((_connAdo != null) && TestConnection(_connAdo.ConnectionString))
            {
                _connStrBuilder.ConnectionString = _connAdo.ConnectionString;
                OnPropertyChanged("ConnectionString");
                OnPropertyChanged("SupportsSchemata");
            }
        }
Exemplo n.º 8
0
        private static bool GetNewConnectionStringFromWizard(out string newConnectionString)
        {
            newConnectionString = null;

            DataLinks dataLinks = new DataLinksClass();
            object    result    = dataLinks.PromptNew();

            if (result != null)
            {
                newConnectionString = ((ADODB.Connection)result).ConnectionString;
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        private void btnConnectString_Click(object sender, EventArgs e)
        {
            var         dlDlg = new DataLinksClass();
            _Connection con   = null;

            con = (_Connection)dlDlg.PromptNew();
            if (con == null)
            {
                return;
            }
            var str = con.ConnectionString;

            if (!str.Contains(MULTI))
            {
                str = str + MULTI;
            }
            tbConnectionString.Text = str;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles event when Edit Connection button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void EditConnCommandClick(object param)
        {
            try
            {
                object adoDbConn = (object)_connAdo;

                DataLinks udl = new DataLinksClass();
                udl.hWnd = _windowHandle != IntPtr.Zero ? _windowHandle.ToInt32() :
                           new WindowInteropHelper(App.Current.MainWindow).Handle.ToInt32();

                if (udl.PromptEdit(ref adoDbConn))
                {
                    if (TestConnection(_connAdo.ConnectionString))
                    {
                        _connStrBuilder.ConnectionString = _connAdo.ConnectionString;
                        OnPropertyChanged("ConnectionString");
                        OnPropertyChanged("SupportsSchemata");
                    }
                }
            }
            catch { _connAdo = null; }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Prompts the user for an OLE DB connection string using the Data Link Properties dialog.
        /// </summary>
        /// <param name="initialString">The initial connection string to display in the dialog. May be null.</param>
        /// <param name="dialogParent">The control to be used as the parent of the Data Link Properties dialog or
        /// null to show it as a non-modal dialog.</param>
        /// <param name="allowedProviderProgID">If the user is only allowed to select one provider the ProgID of
        /// that provider, otherwise null.</param>
        /// <param name="allowedProviderDisplayName">The name of the allowed provider, as shown on the Providers
        /// tab in the Data Link Properties dialog. This parameter is ignored if
        /// <paramref name="allowedProviderProgID"/> is null.</param>
        /// <returns>The new connection configured by the user or null if the user clicked Cancel in the dialog.</returns>
        public static string PromptForConnectionString(string initialString, IWin32Window dialogParent,
                                                       string allowedProviderProgID, string allowedProviderDisplayName)
        {
            DataLinks datalinks = new DataLinksClass();

            datalinks.hWnd = (dialogParent == null ? 0 : (int)dialogParent.Handle);

            while (true)
            {
                Connection connection = new ConnectionClass();

                if (initialString != null && initialString.Length > 0)
                {
                    // If the string doesn't have a Provider specified, but we have allowedProviderProgID then
                    // set it.

                    if (allowedProviderProgID != null && CultureInfo.CurrentCulture.CompareInfo.IndexOf(
                            initialString, "provider", CompareOptions.IgnoreCase) < 0)
                    {
                        initialString = "Provider=" + allowedProviderProgID + ";" + initialString;
                    }

                    connection.ConnectionString = initialString;
                }
                else
                {
                    // Default to MS SQL.
                    connection.ConnectionString = "Provider=" + Constants.OleDb.MsSqlProviderProgID;
                }

                object refConnection = connection;

                if (datalinks.PromptEdit(ref refConnection))
                {
                    connection = (Connection)refConnection;

                    if (allowedProviderProgID == null)
                    {
                        return(connection.ConnectionString);
                    }

                    // Check that the provider is the allowed one.

                    if (connection.Provider == allowedProviderProgID || connection.Provider.StartsWith(allowedProviderProgID + "."))
                    {
                        return(connection.ConnectionString);
                    }

                    // It's not - tell the user and prompt again.

                    string displayName = (allowedProviderDisplayName == null || allowedProviderDisplayName.Length == 0
                                                ? allowedProviderProgID : allowedProviderDisplayName);

                    MessageBox.Show(dialogParent, "You must select '" + displayName + "' on the Provider tab.",
                                    "Edit database connection string", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    return(null);
                }
            }
        }
        /// <summary>
        /// Handles event when Edit Connection button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void EditConnCommandClick(object param)
        {
            try
            {
                object adoDbConn = (object)_connAdo;

                DataLinks udl = new DataLinksClass();
                udl.hWnd = _windowHandle != IntPtr.Zero ? _windowHandle.ToInt32() :
                    new WindowInteropHelper(App.Current.MainWindow).Handle.ToInt32();

                if (udl.PromptEdit(ref adoDbConn))
                {
                    if (TestConnection(_connAdo.ConnectionString))
                    {
                        _connStrBuilder.ConnectionString = _connAdo.ConnectionString;
                        OnPropertyChanged("ConnectionString");
                        OnPropertyChanged("SupportsSchemata");
                    }
                }
            }
            catch { _connAdo = null; }
        }
        /// <summary>
        /// Handles event when Create Connection button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void CreateConnCommandClick(object param)
        {
            DataLinks udl = new DataLinksClass();
            udl.hWnd = _windowHandle != IntPtr.Zero ? _windowHandle.ToInt32() :
                new WindowInteropHelper(App.Current.MainWindow).Handle.ToInt32();
            _connAdo = udl.PromptNew() as ADODB.Connection;

            if ((_connAdo != null) && TestConnection(_connAdo.ConnectionString))
            {
                _connStrBuilder.ConnectionString = _connAdo.ConnectionString;
                OnPropertyChanged("ConnectionString");
                OnPropertyChanged("SupportsSchemata");
            }
        }