예제 #1
0
        public static string GetBuiltConnectionString(string inputConnectionString)
        {
            MSDASC.DataLinks oDL = null;
            string           res = string.Empty;

            try
            {
                oDL = new MSDASC.DataLinksClass();
                ADODB.Connection conn = new ADODB.ConnectionClass();

                conn.ConnectionString = inputConnectionString;
                object oConn = (object)conn;
                if (oDL.PromptEdit(ref oConn))
                {
                    res = conn.ConnectionString;
                }
            }
            catch
            {
                try
                {
                    ADODB._Connection oConn = (ADODB._Connection)oDL.PromptNew();
                    if (oConn != null)
                    {
                        res = oConn.ConnectionString.ToString();
                    }
                }
                catch (Exception ex)
                {
                    MyExceptionHandler.NewEx(ex);
                }
            }

            return(string.IsNullOrEmpty(res) ? null : res);
        }
예제 #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Cursor.Current = Cursors.WaitCursor;
            string tmpReturn = string.Empty;

            MSDASC.DataLinks  dataLinks  = new MSDASC.DataLinksClass();
            ADODB._Connection connection = null;

            if (value.ToString() == String.Empty)
            {
                try
                {
                    connection = (ADODB._Connection)dataLinks.PromptNew();
                    if (connection != null)                    //if cancel is pressed connection is null
                    {
                        tmpReturn = connection.ConnectionString;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                connection = new ADODB.ConnectionClass();
                connection.ConnectionString = value.ToString();

                object oConnection = connection;
                try
                {
                    if ((bool)dataLinks.PromptEdit(ref oConnection))
                    {
                        tmpReturn = connection.ConnectionString;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            Cursor.Current = Cursors.Default;
            return(tmpReturn);
        }
예제 #3
0
        /// <summary>
        /// Задаёт строку соединения с базой и определяет версию SQL-сервера
        /// </summary>
        /// <returns>true - выполнена успешно; false - произошла ошибка</returns>
        /// <remarks>На машине пользователя должны быть установлены "Microsoft ActiveX Data... 2.7" и "Microsoft OLEDB 1.0 Service..." </remarks>
        public bool setConStr()
        {
            sqlVer = SqlVer.UNKNOWN;
            conStr = "";
            try
            {
                //нужно подключить Microsoft ActiveX Data... 2.7 и Microsoft OLEDB 1.0 Service..."
                MSDASC.DataLinks  conDlg = new MSDASC.DataLinks();
                ADODB._Connection adoCon = (ADODB._Connection)conDlg.PromptNew();
                if (adoCon == null)
                {
                    return(false);
                }
                conStr = adoCon.ConnectionString;
                //выясняем какая версия MS SQL Server используется
                if (conStr.IndexOf("SQLOLEDB") >= 0)
                {
                    sqlVer = SqlVer.MSSQL2000;
                }
                if (conStr.IndexOf("SQLNCLI") >= 0)
                {
                    sqlVer = SqlVer.MSSQL2005;
                }
                if (sqlVer == SqlVer.UNKNOWN)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            return(true);
        }