Exemplo n.º 1
0
        //Restore
        public void Restore()
        {
            try
            {
                //Read file form C:\
                string path;
                path = "C:\\Users\\Raymond Mortu\\Documents\\sqlBackup";
                StreamReader file  = new StreamReader(path);
                string       input = file.ReadToEnd();
                file.Close();

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = "mysql";
                psi.RedirectStandardInput  = true;
                psi.RedirectStandardOutput = false;
                psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",
                                              uid, password, server, database);
                psi.UseShellExecute = false;

                Process process = Process.Start(psi);
                process.StandardInput.WriteLine(input);
                process.StandardOutput.Close();
                process.WaitForExit();
                process.Close();
            }
            catch (IOException ex)
            {
                Javascript.Alert("Error, unable to Restore!");
            }
        }
Exemplo n.º 2
0
        //open connection to database
        public bool OpenConnection()
        {
            try
            {
                Javascript.Alert("connected to server!!");

                MySqlConnection connections = new MySqlConnection();

                connections.Open();
                return(true);
            }
            catch (MySqlException ex)
            {
                //When handling errors, you can your application's response based
                //on the error number.
                //The two most common error numbers when connecting are as follows:
                //0: Cannot connect to server.
                //1045: Invalid user name and/or password.
                switch (ex.Number)
                {
                case 0:
                    System.Diagnostics.Debug.WriteLine("Cannot connect to server. Contact administrator");
                    Javascript.Alert("Cannot connect to server. Contact administrator");
                    break;

                case 1045:
                    System.Diagnostics.Debug.WriteLine("Invalid username/Password, please try again");
                    Javascript.Alert("Invalid username/Password, please try again");
                    break;
                }
                return(false);
            }
        }
Exemplo n.º 3
0
 //Close connection
 public bool CloseConnection()
 {
     try
     {
         connection.Close();
         return(true);
     }
     catch (MySqlException ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
         Javascript.Alert(ex.Message);
         return(false);
     }
 }
Exemplo n.º 4
0
        //Backup
        public void Backup()
        {
            try
            {
                DateTime Time        = DateTime.Now;
                int      year        = Time.Year;
                int      month       = Time.Month;
                int      day         = Time.Day;
                int      hour        = Time.Hour;
                int      minute      = Time.Minute;
                int      second      = Time.Second;
                int      millisecond = Time.Millisecond;

                //Save file to C:\ with the current date as a filename
                string path;
                path = "C:\\Users\\Raymond Mortu\\Documents\\sqlBackup" + year + "_" + day + "_" + hour + "_" + minute +
                       "_" + minute + "_" + second + "_" + millisecond + ".sql";

                StreamWriter file = new StreamWriter(path);

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = "mysqldump";
                psi.RedirectStandardInput  = false;
                psi.RedirectStandardOutput = true;
                psi.Arguments       = string.Format(@"-u{0} -{1} -h{2} {3}", uid, password, server, database);
                psi.UseShellExecute = false;

                Process process = Process.Start(psi);

                string output;
                output = process.StandardOutput.ReadToEnd();
                file.WriteLine(output);
                process.WaitForExit();
                file.Close();
                process.Close();
            }
            catch (IOException ex)
            {
                Javascript.Alert("Error, unable to backup!");
            }
        }