예제 #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtServer.Text) || string.IsNullOrEmpty(txtUID.Text) || string.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show("Please enter the required details.");
                    IsConnected = false;
                }
                else
                {
                    lstDbs.Items.Clear();
                    SqlConnection SqlCon = new SqlConnection("server=" + txtServer.Text + ";uid=" + txtUID.Text + ";pwd=" + txtPassword.Text);
                    SqlCon.Open();
                    SqlCommand SqlCom = new SqlCommand();
                    SqlCom.Connection  = SqlCon;
                    SqlCom.CommandType = CommandType.StoredProcedure;
                    SqlCom.CommandText = "sp_databases";

                    System.Data.SqlClient.SqlDataReader SqlDR;
                    SqlDR = SqlCom.ExecuteReader();

                    while (SqlDR.Read())
                    {
                        lstDbs.Items.Add(SqlDR.GetString(0));
                    }

                    SqlDR.Close();
                    SqlCon.Close();

                    IsConnected = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                IsConnected = false;
            }
        }