Exemple #1
0
        //This checks both styles of connections and return false when the second(older) method ALSO fails
        //maybe should've done this with 2 separate methods but thought against it as those 2 new functions
        //would increase overhead and wouldn't be needed again.
        public static bool TestConnection(BackupItem itm)
        {
            //Begin NewStyle check
            MysqlAlias.MySqlConnection conn = null;
            try
            {
                conn = new MysqlAlias.MySqlConnection(itm.ConnectionString());
                conn.Open();
            }
            catch (MysqlAlias.MySqlException)
            {
                //Begin OldStyle Check
                OldMysqlAlias.MySqlConnection old_conn = null;

                try
                {
                    old_conn = new OldMysqlAlias.MySqlConnection(itm.ConnectionString());
                    old_conn.Open();
                }
                catch (MysqlAlias.MySqlException)
                {
                    return false;
                }catch(Exception)
                {
                    return false;
                }
                finally
                {
                    if (old_conn != null)
                    {
                        old_conn.Close();
                    }
                }
                //End OldStyle Check
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            //End NewStyle check
            return true;
        }
Exemple #2
0
        bool backupDatabase(BackupItem bk_itm)
        {
            //This uses the newer version of mysql dll 6.6 ot enable connection to servers that use new style password authemtication (4.1 style)

            string result_folder = bk_itm.SaveTo + "\\" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString("D2") + "-" + DateTime.Now.Day.ToString("D2") + "\\" + bk_itm.Database + "\\";

            MysqlAlias.MySqlConnection conn = null;
            MysqlAlias.MySqlDataReader rdr = null;

            try
            {
                conn = new MysqlAlias.MySqlConnection(bk_itm.ConnectionString());
                conn.Open();
                //get every table in this db
                string stm = "SHOW TABLES";
                MysqlAlias.MySqlCommand cmd = new MysqlAlias.MySqlCommand(stm, conn);
                rdr = cmd.ExecuteReader();

                //deal with directory that .sql files should be saved in
                if (!Directory.Exists(result_folder))
                {
                    Directory.CreateDirectory(result_folder);
                }

                string current_table = "";
                while (rdr.Read())
                {
                    current_table = rdr.GetString(0);
                    // Use ProcessStartInfo class
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.CreateNoWindow = true;
                    startInfo.UseShellExecute = false;
                    startInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\mysqldump.exe";
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    //::@C:\Users\User\Downloads\MySQLWinBackup\MySQLWinBackup\mysqldump.exe
                    startInfo.Arguments = "--host=\"" + bk_itm.Host + "\" --port=\"" + bk_itm.Port + "\" --user=\"" + bk_itm.Username + "\" --password=\"" + bk_itm.PasswordValue + "\" -Q --result-file=\"" + result_folder + "\\" + current_table + ".sql\" \"" + bk_itm.Database + "\" \"" + current_table + "\"";

                    try
                    {
                        // Start the process with the info we specified.
                        // Call WaitForExit and then the using statement will close.
                        using (Process exeProcess = Process.Start(startInfo))
                        {
                            exeProcess.WaitForExit();
                            txtOutput.Text += "Database: " + bk_itm.Database + "   -  table: " + current_table + " done " + Environment.NewLine;
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLog(ex.Message);
                        return false;
                    }
                }
                //progressBar2.PerformStep();
                //if (progressBar2.Value >= progressBar2.Maximum)
                //{
                //    progressBar2.Style = ProgressBarStyle.Marquee;
                //}

            }
            catch (MysqlAlias.MySqlException ex)
            {
                ErrorLog(ex.Message);
                return false;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return true;
        }