Пример #1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     iniConfig cfg = new iniConfig();
     cfg.getConfigDatabase();
     textBox1.Text = cfg.db_host;
     textBox2.Text = cfg.db_password;
     textBox3.Text = cfg.db_user;
     textBox4.Text = cfg.db_database;
 }
Пример #2
0
        public static MySqlConnection ObtenerConexion()
        {
            iniConfig cfg = new iniConfig();
            cfg.getConfigDatabase();
            string servidor = cfg.db_host;
            string pwd = cfg.db_password;
            string usuario = cfg.db_user;
            string db = cfg.db_database;

            string cdnCon = "server=" + servidor + "; database=" + db + "; Uid=" + usuario + "; pwd=" + pwd + ";";
            MySqlConnection conectar = new MySqlConnection(cdnCon);
            try
            {
                conectar.Open();
            }
            catch (MySqlException e)
            {
                MessageBox.Show("Ocurrio un Error al realizar la conexión a la base de datos \n "+e.Message,"Error en la conexión",MessageBoxButtons.OK,MessageBoxIcon.Error);
                Application.Exit();
            }
            return conectar;
        }