Exemplo n.º 1
0
        private void ChangeDB()
        {
            cmbTables.Enabled = false;
            if (settings.ProviderName == SQLProvider.My_SQL)
            {
                if (!string.IsNullOrWhiteSpace(tbHost?.Text))
                {
                    settings.Host     = tbHost?.Text;
                    settings.Port     = int.TryParse(tbPort?.Text, out int port) ? port : 0;
                    settings.Database = cmbDataBases?.Items?.Count > 0 ? cmbDataBases?.SelectedItem?.ToString() : selectedDB;
                    settings.Username = tbUserName?.Text;
                    settings.Password = tbPassword?.Text;
                }
                else
                {
                    tbResultShow.AppendLine("Check the correctness of the entered data:");
                    tbResultShow.AppendLine("Host: " + tbHost?.Text);
                    return;
                }

                try
                {
                    MySQLUtils     mySQL = new MySQLUtils(settings);
                    DataTable      dt    = mySQL.GetTable("SHOW TABLES");
                    IList <string> list  = new List <string>();
                    foreach (DataRow r in dt.Rows)
                    {
                        list.Add(r[0].ToString());
                    }

                    if (list?.Count > 0)
                    {
                        cmbTables.DataSource = list;
                        cmbTables.Enabled    = true;

                        settings.Table = cmbTables?.Items?.Count > 0 ? cmbTables?.SelectedItem?.ToString() : null;

                        tbResultShow.AppendLine($"DB exists and table {settings.Table} are selected.");
                        tbResultShow.AppendLine("Please will select needed DataBase!");
                    }
                }
                catch (MySqlException excpt)
                {
                    tbResultShow.AppendLine(excpt.Message + ":");
                    tbResultShow.AppendLine(excpt.ToString());
                }
                catch (Exception excpt)
                {
                    tbResultShow.AppendLine(excpt.Message + ":");
                    tbResultShow.AppendLine(excpt.ToString());
                }
            }
            else if (settings.ProviderName == SQLProvider.MS_SQL)
            {
                throw new NotImplementedException();
            }

            tbName.Text = SetNameConnection();
        }
Exemplo n.º 2
0
        private ISQLConnectionSettings CheckMySQLDB(ISQLConnectionSettings tmpSettings)
        {
            ISQLConnectionSettings newSettings = new SQLConnectionSettings(tmpSettings);

            newSettings.Host     = tbHost?.Text;
            newSettings.Port     = int.TryParse(tbPort?.Text, out int port) ? port : 0;
            newSettings.Database = cmbDataBases?.SelectedItem?.ToString() ?? selectedDB;
            newSettings.Username = tbUserName?.Text;
            newSettings.Password = tbPassword?.Text;
            MySQLUtils mySQL = new MySQLUtils(newSettings);

            try
            {
                using (DataTable dt = mySQL.GetTable("SHOW DATABASES"))
                {
                    IList <string> list = new List <string>();
                    foreach (DataRow r in dt.Rows)
                    {
                        list.Add(r[0].ToString());
                    }

                    if (list?.Count > 0)
                    {
                        cmbDataBases.DataSource = list;
                        cmbDataBases.Enabled    = true;
                        newSettings.Database    = list[0];

                        tbResultShow.AppendLine("The inputed data are correct.");
                    }
                }
            }
            catch (MySqlException excpt)
            {
                tbResultShow.AppendLine("My SQL error - " + excpt.Message + ":");
                tbResultShow.AppendLine(excpt.ToString());
            }
            catch (Exception excpt)
            {
                tbResultShow.AppendLine(excpt.Message + ":");
                tbResultShow.AppendLine(excpt.ToString());
            }

            return(newSettings);
        }
Exemplo n.º 3
0
        private ISQLConnectionSettings CheckMySQLDB(ISQLConnectionSettings tmpSettings)
        {
            ISQLConnectionSettings newSettings = MakeFromControls(tmpSettings, MYSQL);

            MySQLUtils mySQL = new MySQLUtils(newSettings);

            try
            {
                using DataTable dt = mySQL.GetTable("SHOW DATABASES", 5);
                tbResultShow.AppendLine(mySQL.GetConnection().ToString());
                tbResultShow.AppendLine("Строка подключения: " + mySQL.connString);

                IList <string> list = (from DataRow r in dt.Rows select r[0]?.ToString()).ToList();

                if (list?.Count > 0)
                {
                    cmbDataBases.DataSource = list;
                    cmbDataBases.Enabled    = true;
                    newSettings.Database    = list[0];

                    tbResultShow.AppendLine("The inputed data are correct.");
                }
                else
                {
                    tbResultShow.AppendLine("Указаны некорректны данные или отсутствует подключение к серверу!");
                }
            }
            catch (MySqlException error)
            {
                newSettings = null;
                tbResultShow.AppendLine("My SQL error - " + error.Message + ":");
                tbResultShow.AppendLine(error.ToString());
            }
            catch (Exception error)
            {
                newSettings = null;
                tbResultShow.AppendLine(error.Message + ":");
                tbResultShow.AppendLine(error.ToString());
            }

            return(newSettings);
        }