Esempio n. 1
0
        /// <summary>
        /// Copy the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCopy_Click(object sender, EventArgs e)
        {
            cDatabaseCopy dbc = new cDatabaseCopy();

            dbc.Progress    += new ProgressEventHandler(OperationProgress);
            dbc.StepChanged += new StepsEventHandler(StepChanged);


            if (PreCheckSettings())
            {
                try
                {
                    dbc.CopyDatabase(txtSourceDir.Text, cmbFromDatabase.Text, cmbToDatabase.Text,
                                     txtDestDir.Text, txtDestBackupDir.Text, txtDestLogDir.Text, cmbFromServer.Text, cmbToServer.Text,
                                     txtFromServerUser.Text, txtFromServerPassword.Text,
                                     chkFromServerIntegrated.Checked, txtToServerUser.Text, txtToServerPassword.Text,
                                     chkToServerIntegrated.Checked);
                }
                catch (Exception ex)
                {
                    //reset status information
                    tsStatus.Text = "Error.";
                    pbCopy.Value  = 0;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Title = "SQL Server Database Copy Tool";

            _settings = new cSettings(Application.StartupPath + "\\config.xml");

            //check if we are in commandline with arguments
            if (args.Length > 0)
            {
                if (args.Length == 4)
                {
                    //do things
                    string sFromServer   = args[0];
                    string sToServer     = args[1];
                    string sFromDatabase = args[2];
                    string sToDatabase   = args[3];

                    if (!PreCheckServer(sFromServer) || !PreCheckServer(sToServer))
                    {
                        Application.Exit();
                    }
                    else
                    {
                        cDatabaseCopy dbc = new cDatabaseCopy();
                        dbc.Progress    += new ProgressEventHandler(OperationProgress);
                        dbc.StepChanged += new StepsEventHandler(StepChanged);

                        try
                        {
                            dbc.CopyDatabase(_settings.GetServerDefaultBackupdir(sFromServer),
                                             sFromDatabase,
                                             sToDatabase,
                                             _settings.GetServerDefaultDatadir(sToServer),
                                             _settings.GetServerDefaultBackupdir(sToServer),
                                             _settings.GetServerDefaultLogdir(sToServer),
                                             sFromServer,
                                             sToServer,
                                             _settings.GetServerUsername(sFromServer),
                                             _settings.GetServerPassword(sFromServer),
                                             _settings.GetServerIntegratedSecurity(sFromServer),
                                             _settings.GetServerUsername(sToServer),
                                             _settings.GetServerPassword(sToServer),
                                             _settings.GetServerIntegratedSecurity(sToServer));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine("Exiting...");
                            Application.Exit();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No chance...! Use DbCopyTool.exe YOUR_FROM_SERVER YOUR_TO_SERVER YOUR_FROM_DB YOUR_TO_DB");
                    Console.WriteLine("Exiting...");
                }
            }
            else
            {
                //hide console
                setConsoleWindowVisibility(false, Console.Title);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                frmDBTools main = new frmDBTools();
                Application.Run(main);
            }

            setConsoleWindowVisibility(true, Console.Title);
        }