Example #1
0
        private void ExportDB1()
        {
            string   strDatabase           = @"dbPuls3060Medlem";
            string   strDatabaseBackupfile = this.DBBackupFolder.Text + @"\" + strDatabase + @".bacpac";
            string   ConnectionString      = @"Server=qynhbd9h4f.database.windows.net;Database=dbPuls3060Medlem;User ID=sqlUser;Password=Puls3060;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
            DateTime Nu  = DateTime.Now;
            string   fdt = Nu.ToString("dd-MM-yyyy HH:mm");

            this.MessageLine1.Text      = strDatabase + " Start Backup";
            this.MessageLine1.ForeColor = System.Drawing.Color.DodgerBlue;
            this.Refresh();
            try
            {
                Microsoft.SqlServer.Dac.DacServices Services = new Microsoft.SqlServer.Dac.DacServices(ConnectionString);
                Services.ExportBacpac(strDatabaseBackupfile, @"dbPuls3060Medlem");
                this.MessageLine1.Text      = strDatabase + " Backup OK " + fdt;
                this.MessageLine1.ForeColor = System.Drawing.Color.DodgerBlue;
                this.Refresh();
            }
            catch
            {
                this.MessageLine1.Text      = strDatabase + " Not Backed up " + fdt;
                this.MessageLine1.ForeColor = System.Drawing.Color.Red;
                this.Refresh();
            }
        }
Example #2
0
        void Backup(XmlNode n, string id)
        {
            var toFile  = Program.Shared.ReplaceTags(Util.GetStr(n, "toFile"));
            var type    = Program.Shared.ReplaceTags(Util.GetStr(n, "type", "bacpac"));
            var connStr = Program.Shared.Databases[id];
            var dbName  = Util.GetConfigData(connStr, "Initial Catalog");

            Program.Shared.WriteLogLine("Starting Database Backup.");
            if (type.ToLower() == "bacpac")
            {
                var ds = new Microsoft.SqlServer.Dac.DacServices(connStr);
                ds.ExportBacpac(toFile, dbName);
            }
            else if (type.ToLower() == "bak")
            {
                var timeout     = Util.GetStr(n, "timeout", "1800").IsNumber()?Convert.ToInt32(Util.GetStr(n, "timeout", "1800")):1800;
                var withOptions = Util.GetStr(n, "withOptions");
                Util.Execute("backup database " + dbName + " to disk='" + toFile + "' " + withOptions, connStr, timeout);
            }
            Program.Shared.DbBackups.Add(toFile);
            var toVar = Util.GetStr(n, "toVar");

            if (!string.IsNullOrEmpty(toVar))
            {
                lock (Program.Shared.LockVariables) { Program.Shared.Variables[toVar + ";" + Program.Shared.GetSequence()] = toFile; }
            }
            Program.Shared.WriteLogLine(String.Format("Finished Database Backup (File: {0}; Size: {1}).", toFile, Util.GetFileSize(new FileInfo(toFile).Length)));
        }
Example #3
0
        private void ExportDB2()
        {
            string   strSQLServer          = this.SQLServer.Text; //@"(localdb)\localdb";
            string   strDatabase           = this.Database.Text;;
            string   strDatabaseBackupfile = this.DBBackupFolder.Text + @"\" + strDatabase + @".bacpac";
            string   ConnectionString      = @"Server=" + strSQLServer + @";Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;";
            DateTime Nu  = DateTime.Now;
            string   fdt = Nu.ToString("dd-MM-yyyy HH:mm");

            this.MessageLine2.Text      = strDatabase + " Start Backup";
            this.MessageLine2.ForeColor = System.Drawing.Color.DodgerBlue;
            this.Refresh();

            try
            {
                Microsoft.SqlServer.Dac.DacServices Services = new Microsoft.SqlServer.Dac.DacServices(ConnectionString);
                Services.ExportBacpac(strDatabaseBackupfile, strDatabase);
                this.MessageLine2.Text      = strDatabase + " Backup OK " + fdt;
                this.MessageLine2.ForeColor = System.Drawing.Color.DodgerBlue;
                this.Refresh();
            }
            catch
            {
                this.MessageLine2.Text      = strDatabase + " Not Backed up " + fdt;
                this.MessageLine2.ForeColor = System.Drawing.Color.Red;
                this.Refresh();
            }
        }