Example #1
0
        private bool TestConnecting()
        {
            bool result = false;

            try
            {
                DataOracle dataOracle = new DataOracle();
                dataOracle.host     = txtHost.Text;
                dataOracle.port     = txtPort.Text;
                dataOracle.sid      = txtSid.Text;
                dataOracle.user     = txtUser.Text;
                dataOracle.password = txtPassword.Text;
                DBConnecting.conn   = DBConnecting.GetDBConnection(dataOracle);
                DBConnecting.conn.Open();
                lbStatus.ForeColor = Color.LimeGreen;
                lbStatus.Text      = "Successful connection";
                result             = true;
                DBConnecting.conn.Close();
            }
            catch (Exception ex)
            {
                DBConnecting.conn.Close();
                lbStatus.ForeColor = Color.Red;
                lbStatus.Text      = "Connection failed";
                MessageBox.Show("Lỗi: " + ex.Message, "Thông báo!");
            }
            return(result);
        }
Example #2
0
        private void UpdateConfigDatabase()
        {
            List <string> list = new List <string>();

            using (StreamReader streamReader = new StreamReader("ConfigConnect"))
            {
                string item;
                while ((item = streamReader.ReadLine()) != null)
                {
                    list.Add(item);
                }
            }
            using (StreamWriter streamWriter = new StreamWriter("ConfigConnect"))
            {
                oracle          = new DataOracle();
                oracle.host     = txtHost.Text;
                oracle.port     = txtPort.Text;
                oracle.sid      = txtSid.Text;
                oracle.user     = txtUser.Text;
                oracle.password = txtPassword.Text;
                foreach (string item2 in list)
                {
                    if (!item2.Contains("="))
                    {
                        streamWriter.WriteLine(item2);
                    }
                    else
                    {
                        string text = item2.Substring(0, item2.IndexOf("="));
                        switch (text.ToLower())
                        {
                        case "host":
                            streamWriter.WriteLine("host=" + oracle.host);
                            break;

                        case "port":
                            streamWriter.WriteLine("port=" + oracle.port);
                            break;

                        case "sid":
                            streamWriter.WriteLine("sid=" + oracle.sid);
                            break;

                        case "user":
                            streamWriter.WriteLine("user="******"password":
                            streamWriter.WriteLine("password="******"Lưu thành công");
        }