Ejemplo n.º 1
0
        /// <summary>
        /// 连接  测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbbServer.Text))
            {
                MessageBox.Show("服务器不能为空!");
                return;
            }

            if (cbbShenFenRZ.SelectedIndex == 1 && string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBox.Show("登陆名不能为空!");
                return;
            }

            try
            {
                IDbObject dbObejct    = new DbObject(cbbShenFenRZ.SelectedIndex == 0, cbbServer.Text, txtUserName.Text, txtPassword.Text);
                DataTable DBNameTable = dbObejct.GetDBList();
                cbbDatabase.Items.Clear();
                cbbDatabase.Items.Add("全部");
                foreach (DataRow dr in DBNameTable.Rows)
                {
                    cbbDatabase.Items.Add(dr[0].ToString());
                }

                cbbDatabase.Enabled       = true;
                cbbDatabase.SelectedIndex = 0;
                MessageBox.Show("连接成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                cbbDatabase.Enabled = false;
            }
        }