예제 #1
0
        private void txtBaglantiCumle_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            ADODB._Connection ADOcon;
            MSDASC.DataLinks  mydlg = new MSDASC.DataLinks();
            ADOcon = (ADODB._Connection)mydlg.PromptNew();

            if (txtSQLSunucusu.Text == "" || txtSQLSunucusu.Text == null)
            {
                MessageBox.Show("Lütfen SQL Sunucusu seçin!");
                txtSQLSunucusu.Focus();
            }
            else
            {
                ADOcon.Open(txtSQLSunucusu.Text, "Makrosoft", "Makrosoft", 0);
            }


            if (ADOcon.State == 1)
            {
                MessageBox.Show("Bağlantı açıldı");
                ADOcon.Close();
            }
            else
            {
                MessageBox.Show("Bağlantı açılamadı!!");
            }
        }
예제 #2
0
        private string PromptForConnectionString(MetaConnection connection, string currentConnectionString, string initialConnectionString)
        {
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinks();

            string generatedConnectionString = currentConnectionString;
            string resultConnectionString    = "";

            ADODB.Connection dialogConnection = (ADODB.Connection)dataLinks.PromptNew();
            if (dialogConnection != null)
            {
                connection.UserName       = "";
                connection.ClearPassword  = "";
                generatedConnectionString = dialogConnection.ConnectionString.ToString();

                if (dialogConnection.Properties["Password"] != null && dialogConnection.Properties["Password"].Value != null && !generatedConnectionString.Contains("Password="******";Password={0}", dialogConnection.Properties["Password"].Value);
                }

                foreach (string config in generatedConnectionString.Split(';'))
                {
                    if (config.StartsWith("User ID="))
                    {
                        connection.UserName = config.Replace("User ID=", "").Replace("\"", "");
                        continue;
                    }
                    if (config.StartsWith("Password="******"Password="******"");
                        continue;
                    }
                    if (resultConnectionString != "")
                    {
                        resultConnectionString += ";";
                    }
                    resultConnectionString += config;
                }

                if (!string.IsNullOrEmpty(connection.UserName) && string.IsNullOrEmpty(connection.ClearPassword))
                {
                    MessageBox.Show("Note that the Password is empty (Perhaps did you not check the option 'Allow Saving Password')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                DatabaseType newType = GetDatabaseType(resultConnectionString);
                if (newType != connection.DatabaseType)
                {
                    connection.DatabaseType = newType;
                    MessageBox.Show(string.Format("The database type has been set to {0}", newType), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                resultConnectionString = initialConnectionString;
            }
            return(resultConnectionString);
        }
예제 #3
0
파일: ASQL-A3.cs 프로젝트: WilliamPring/SET
 /// <summary>
 /// ConnectionString builder for source
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ConnectionStringSourceBtn_Click(object sender, EventArgs e)
 {
     object _con = null;
     MSDASC.DataLinks _link = new MSDASC.DataLinks();
     _con = _link.PromptNew();
     if (_con != null)
     {
         sourceConnectionString = ((ADODB.Connection)_con).ConnectionString;
     }
 }
예제 #4
0
 private void brnCSDialog_Click(object sender, EventArgs e)
 {
     MSDASC.DataLinks  csDlg = new MSDASC.DataLinks();
     ADODB._Connection ADOCon;
     ADOCon     = (ADODB._Connection)csDlg.PromptNew();
     tbxCS.Text = (string)ADOCon.ConnectionString;
     if (ADOCon.State == 1)
     {
         ADOCon.Close();
     }
 }
예제 #5
0
        public void ChangeConnectionString()
        {
            MSDASC.DataLinks dlg = new MSDASC.DataLinks();
            object result = dlg.PromptNew();

            string connectionString = "";
            if (result != null) {
                ADODB.Connection adodbConn = (ADODB.Connection)result;
                connectionString = adodbConn.ConnectionString;
            }
            _Form.ConnectionString = connectionString;
        }
예제 #6
0
        private string PromptForConnectionString(MetaConnection connection, string currentConnectionString, string initialConnectionString)
        {
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinks();

            string generatedConnectionString = currentConnectionString;
            string resultConnectionString = "";

            ADODB.Connection dialogConnection = (ADODB.Connection)dataLinks.PromptNew();
            if (dialogConnection != null)
            {
                connection.UserName = "";
                connection.ClearPassword = "";
                generatedConnectionString = dialogConnection.ConnectionString.ToString();

                if (dialogConnection.Properties["Password"] != null && dialogConnection.Properties["Password"].Value != null && !generatedConnectionString.Contains("Password="******";Password={0}", dialogConnection.Properties["Password"].Value);
                }

                foreach (string config in generatedConnectionString.Split(';'))
                {
                    if (config.StartsWith("User ID="))
                    {
                        connection.UserName = config.Replace("User ID=", "").Replace("\"", "");
                        continue;
                    }
                    if (config.StartsWith("Password="******"Password="******"");
                        continue;
                    }
                    if (resultConnectionString != "") resultConnectionString += ";";
                    resultConnectionString += config;
                }

                if (!string.IsNullOrEmpty(connection.UserName) && string.IsNullOrEmpty(connection.ClearPassword)) MessageBox.Show("Note that the Password is empty (Perhaps did you not check the option 'Allow Saving Password')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                DatabaseType newType = GetDatabaseType(resultConnectionString);
                if (newType != connection.DatabaseType)
                {
                    connection.DatabaseType = newType;
                    MessageBox.Show(string.Format("The database type has been set to {0}", newType), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                resultConnectionString = initialConnectionString;
            }
            return resultConnectionString;
        }
        static public IConnection CreateFromDataConnectionLink()
        {
            ADODB._Connection AdoConnection;
            MSDASC.DataLinks  dataLink   = new MSDASC.DataLinks();
            IConnection       connection = null;

            AdoConnection = null;
            AdoConnection = (ADODB._Connection)dataLink.PromptNew();

            if ((AdoConnection != null) && (AdoConnection.ConnectionString != ""))
            {
                connection = CreateConnectionObject(AdoConnection.ConnectionString);
            }

            return(connection);
        }
예제 #8
0
        private void btn_crear_ocon_Click(object sender, EventArgs e)
        {
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinks();

            ADODB._Connection connection;

            try
            {
                connection = (ADODB._Connection)dataLinks.PromptNew();

                this.txtCadConExt.Text = connection.ConnectionString.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #9
0
 public static string GetConnectionString()
 {
     try
     {
         dynamic          _con  = null;
         MSDASC.DataLinks _link = new MSDASC.DataLinks();
         _con = _link.PromptNew();
         if (_con != null)
         {
             // sourceConnectionString = ((ADODB.Connection)_con).ConnectionString;
             return(_con.ConnectionString);
         }
     }
     catch (Exception)
     {
     }
     return(null);
 }
예제 #10
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);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Queries data source (used system dialog).
        /// </summary>
        /// <param name="fromFile">Data source is file flag.</param>
        /// <param name="owner">Dialog owner (can be null).</param>
        /// <param name="type">Data source files filter type.</param>
        /// <returns>TRUE only if real DataSource selected.
        /// FALSE - error detected or cancel selected.</returns>
        /// <remarks>Recall supported.</remarks>
        public static bool QueryDataSource(bool fromFile, Window owner, FilterType type)
        {
            if (fromFile)
            {   // User select file
                // show Open File Dialog (NOTE: WPF not supported WinForms)
                var ofd = new Microsoft.Win32.OpenFileDialog();
                ofd.RestoreDirectory = true;

                switch (type)
                {
                    case FilterType.AllSupported:
                        ofd.Filter = OPENFILE_DIALOG_FILTER_ALLTYPES;
                        ofd.FilterIndex = 8;
                        break;

                    case FilterType.WithoutShape:
                        ofd.Filter = OPENFILE_DIALOG_FILTER_WITHSHAPE;
                        ofd.FilterIndex = 7;
                        break;

                    case FilterType.OnlyShape:
                        ofd.Filter = OPENFILE_DIALOG_FILTER_ONLYSHAPE;
                        ofd.FilterIndex = 2;
                        break;

                    default:
                        Debug.Assert(false); // NOTE: not supported
                        break;
                }

                if (true != ofd.ShowDialog(owner)) // Result could be true, false, or null
                    return false;

                FilePath = ofd.FileName;
            }
            else
            {   // User select data source/server

                // Reference DataLinks
                // NOTE: Reference
                //    COM.Microsoft OLE DB Service Component 1.0 Type Library
                //    (Was MSDASC.dll)
                // SEE:
                //    http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp

                // show Data Links Properties dialog
                var dataLinks = new MSDASC.DataLinks();
                WindowInteropHelper helper = new WindowInteropHelper(owner);
                HwndSource _hwndSource = HwndSource.FromHwnd(helper.Handle);
                dataLinks.hWnd = (int)_hwndSource.Handle;
                var connection = dataLinks.PromptNew() as ADODB.Connection;
                if (null == connection)
                    return false;

                ConnectionString = connection.ConnectionString;
            }

            return true;
        }
예제 #12
0
        private void toolStripButtonConnect_Click(object sender, EventArgs e)
        {
            MSDASC.DataLinks mydlg  = new MSDASC.DataLinks();
            CDataAdaHelper   OleCon = new CDataAdaHelper();

            ADODB._Connection ADOcon;
            bool bEdit = false;

            //OleCon.ConnectString = CAppOption.m_sDbConnectString;
            if (CAppOption.m_sDbConnectString == String.Empty)
            {
                try
                {
                    //Cast the generic object that PromptNew returns to an ADODB._Connection.
                    ADOcon = (ADODB._Connection)mydlg.PromptNew();
                    OleCon.ConnectString = ADOcon.ConnectionString;

                    bEdit = true;
                }
                catch (Exception ex)
                {
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }
            else
            {
                ADOcon = new ADODB.ConnectionClass();
                ADOcon.ConnectionString = CAppOption.m_sDbConnectString;
                //set local COM compatible data type
                object oConnection = ADOcon;
                try
                {
                    //prompt user to edit the given connect string
                    if ((bool)mydlg.PromptEdit(ref oConnection))
                    {
                        //处理
                    }
                    OleCon.ConnectString = ADOcon.ConnectionString;

                    bEdit = true;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("服务连接不成功,请重新设置连接!");
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }

            if (bEdit == true)
            {
                try
                {
                    //OleCon.Db.Open();
                    OleCon.Open();

                    if (OleCon.IsOpen)
                    {
                        CAppOption.m_sDbConnectString = OleCon.ConnectString;
                        //OleCon.Db.Close();
                        OleCon.Close();


                        CGlobalInstance.Instance.DbAdaHelper.ConnectString = CAppOption.m_sDbConnectString;
                        CAppOption.SaveData();
                    }
                    else
                    {
                        MessageBox.Show("连接无效,无法连接数据库");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接无效,无法连接数据库(注意请选择允许保存密码)!");
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }
        }
		static public IConnection CreateFromDataConnectionLink()
		{
			ADODB._Connection AdoConnection;
			MSDASC.DataLinks dataLink = new MSDASC.DataLinks();
			IConnection connection = null;

			AdoConnection = null;
			AdoConnection = (ADODB._Connection)dataLink.PromptNew();

			if ((AdoConnection != null) && (AdoConnection.ConnectionString != ""))
			{
				connection = CreateConnectionObject(AdoConnection.ConnectionString);
			}

			return connection;
		}
예제 #14
0
 // http://stackoverflow.com/questions/2205993/winforms-connection-properties-dialog-for-configuration-string
 private string getConnectionString()
 {
     string strConnString = "";
     object _con = null;
     MSDASC.DataLinks _link = new MSDASC.DataLinks();
     _con = _link.PromptNew();
     if (_con == null)
     {
         strConnString = string.Empty;
     }
     else
     {
         strConnString = ((ADODB.Connection)_con).ConnectionString;
     }
     return strConnString;
 }
예제 #15
0
        private string PromptForConnectionString(MetaConnection connection, string currentConnectionString, string initialConnectionString)
        {
            // Try with DataConnectionDialog, but unable to select OleDbSource first... we keep MSDASC :-(
            //Update with VS 2017, still no easy/standard way to do it... we keep MSDASC :-(

            /*    DataConnectionDialog dcd = new DataConnectionDialog();
             *
             * DataSource.AddStandardDataSources(dcd);
             * dcd.SelectedDataSource = DataSource.OdbcDataSource;
             *
             * //            dcd.DataSources.Add(DataSource.OdbcDataSource);
             * //            dcd.DataSources.Add(DataSource.);
             *
             * if (DataConnectionDialog.Show(dcd) == DialogResult.OK)
             * {
             * }
             *
             */
            MSDASC.DataLinks dataLinks = new MSDASC.DataLinks();

            string generatedConnectionString = currentConnectionString;
            string resultConnectionString    = "";

            ADODB.Connection dialogConnection = (ADODB.Connection)dataLinks.PromptNew();
            if (dialogConnection != null)
            {
                connection.UserName       = "";
                connection.ClearPassword  = "";
                generatedConnectionString = dialogConnection.ConnectionString.ToString();

                if (dialogConnection.Properties["Password"] != null && dialogConnection.Properties["Password"].Value != null && !generatedConnectionString.Contains("Password="******";Password={0}", dialogConnection.Properties["Password"].Value);
                }

                foreach (string config in generatedConnectionString.Split(';'))
                {
                    if (config.StartsWith("User ID="))
                    {
                        connection.UserName = config.Replace("User ID=", "").Replace("\"", "");
                        continue;
                    }
                    if (config.StartsWith("Password="******"Password="******"");
                        continue;
                    }
                    if (resultConnectionString != "")
                    {
                        resultConnectionString += ";";
                    }
                    resultConnectionString += config;
                }

                if (!string.IsNullOrEmpty(connection.UserName) && string.IsNullOrEmpty(connection.ClearPassword))
                {
                    MessageBox.Show("Note that the Password is empty (Perhaps did you not check the option 'Allow Saving Password')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                DatabaseType newType = GetDatabaseType(resultConnectionString);
                if (newType != connection.DatabaseType)
                {
                    connection.DatabaseType = newType;
                    MessageBox.Show(string.Format("The database type has been set to {0}", newType), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                resultConnectionString = initialConnectionString;
            }
            return(resultConnectionString);
        }
예제 #16
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Queries data source (used system dialog).
        /// </summary>
        /// <param name="fromFile">Data source is file flag.</param>
        /// <param name="owner">Dialog owner (can be null).</param>
        /// <param name="type">Data source files filter type.</param>
        /// <returns>TRUE only if real DataSource selected.
        /// FALSE - error detected or cancel selected.</returns>
        /// <remarks>Recall supported.</remarks>
        static public bool QueryDataSource(bool fromFile, Window owner, FilterType type)
        {
            if (fromFile)
            {   // User select file
                // show Open File Dialog (NOTE: WPF not supported WinForms)
                var ofd = new Microsoft.Win32.OpenFileDialog();
                ofd.RestoreDirectory = true;

                switch (type)
                {
                case FilterType.AllSupported:
                    ofd.Filter      = OPENFILE_DIALOG_FILTER_ALLTYPES;
                    ofd.FilterIndex = 8;
                    break;

                case FilterType.WithoutShape:
                    ofd.Filter      = OPENFILE_DIALOG_FILTER_WITHSHAPE;
                    ofd.FilterIndex = 7;
                    break;

                case FilterType.OnlyShape:
                    ofd.Filter      = OPENFILE_DIALOG_FILTER_ONLYSHAPE;
                    ofd.FilterIndex = 2;
                    break;

                default:
                    Debug.Assert(false);     // NOTE: not supported
                    break;
                }

                if (true != ofd.ShowDialog(owner)) // Result could be true, false, or null
                {
                    return(false);
                }

                FilePath = ofd.FileName;
            }
            else
            {   // User select data source/server
                // Reference DataLinks
                // NOTE: Reference
                //    COM.Microsoft OLE DB Service Component 1.0 Type Library
                //    (Was MSDASC.dll)
                // SEE:
                //    http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp

                // show Data Links Properties dialog
                var dataLinks = new MSDASC.DataLinks();
                WindowInteropHelper helper      = new WindowInteropHelper(owner);
                HwndSource          _hwndSource = HwndSource.FromHwnd(helper.Handle);
                dataLinks.hWnd = (int)_hwndSource.Handle;
                var connection = dataLinks.PromptNew() as ADODB.Connection;
                if (null == connection)
                {
                    return(false);
                }

                ConnectionString = connection.ConnectionString;
            }

            return(true);
        }