Esempio n. 1
0
        public void ExtractAction()
        {
            ServerConnection connection = this.GetServerConnection(this.database);

            DacStore dacStore = null;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Extract started: {0}", DateTime.Now);

            try
            {
                sw.Start();

                // Get a DacStore for the current connection
                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                DacExtractionUnit deu = new DacExtractionUnit(connection, this.database);

                deu.Version = new Version(1, 0, 0, 0);
                deu.Description = string.Empty;
                deu.TypeName = this.database;

                DacExtractValidationResult result = deu.Extract(this.fileName);

                if (result.ErrorObjects.Count > 0)
                {
                    foreach (var error in result.ErrorObjects)
                    {
                        Console.WriteLine("[ERROR] {0}: {1}", error.Name, error.Description);
                    }
                }

                sw.Stop();

                FileInfo fi = new FileInfo(this.fileName);

                Console.WriteLine("Extract Complete.  Total time: {0}", sw.Elapsed.ToString());
                Console.WriteLine("Output file: {0} Size: {1} bytes", this.fileName, fi.Length);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                if (dacStore != null)
                {
                    this.EventUnsubscribe(dacStore);
                }
            }
        }
Esempio n. 2
0
        public void ExtractAction()
        {
            ServerConnection connection = this.GetServerConnection(this.database);

            DacStore dacStore = null;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Extract started: {0}", DateTime.Now);

            try
            {
                sw.Start();

                // Get a DacStore for the current connection
                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                DacExtractionUnit deu = new DacExtractionUnit(connection, this.database);

                deu.Version     = new Version(1, 0, 0, 0);
                deu.Description = string.Empty;
                deu.TypeName    = this.database;

                DacExtractValidationResult result = deu.Extract(this.fileName);

                if (result.ErrorObjects.Count > 0)
                {
                    foreach (var error in result.ErrorObjects)
                    {
                        Console.WriteLine("[ERROR] {0}: {1}", error.Name, error.Description);
                    }
                }

                sw.Stop();

                FileInfo fi = new FileInfo(this.fileName);

                Console.WriteLine("Extract Complete.  Total time: {0}", sw.Elapsed.ToString());
                Console.WriteLine("Output file: {0} Size: {1} bytes", this.fileName, fi.Length);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                if (dacStore != null)
                {
                    this.EventUnsubscribe(dacStore);
                }
            }
        }
Esempio n. 3
0
        public void ImportAction()
        {
            DacStore  dacStore = null;
            Stopwatch sw       = new Stopwatch();

            try
            {
                Console.WriteLine("Import started: {0}", DateTime.Now);

                ServerConnection connection = this.GetServerConnection(null);

                sw.Start();

                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                // Build the deployment properties.
                DatabaseDeploymentProperties ddp = new DatabaseDeploymentProperties(connection, this.database);

                // Set the azure editions (defaults will accept standard Azure account settings)
                ddp.AzureEdition = this.azureEdition;

                if (this.azureSize > 0)
                {
                    ddp.AzureMaxSize = this.azureSize;
                }

                // DENALI CTP3 version and earlier use these arguments
                dacStore.Import(ddp, this.fileName);

                // DAC Versions after Aug 2011 will have these arguments
                // dacStore.Import(this.fileName, ddp);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                sw.Stop();
                Console.WriteLine("Import Complete.  Total time: {0}", sw.Elapsed.ToString());

                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 4
0
        internal void EventUnsubscribe(DacStore dacStore)
        {
            if (dacStore != null)
            {
                // The finished action is fired after a dac action has completed
                dacStore.DacActionFinished -= new EventHandler<DacActionEventArgs>(dacStore_DacActionFinished);

                // The initialized event is fired when a dac action object is allocated (verbose)
                //dacStore.DacActionInitialized -= new EventHandler<DacActionEventArgs>(dacStore_DacActionInitialized);

                // The started action is fired before any work has started on the event
                dacStore.DacActionStarted -= new EventHandler<DacActionEventArgs>(dacStore_DacActionStarted);
            }
        }
Esempio n. 5
0
        public void ImportAction()
        {
            DacStore dacStore = null;
            Stopwatch sw = new Stopwatch();

            try
            {
                Console.WriteLine("Import started: {0}", DateTime.Now);

                ServerConnection connection = this.GetServerConnection(null);

                sw.Start();

                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                // Build the deployment properties.
                DatabaseDeploymentProperties ddp = new DatabaseDeploymentProperties(connection, this.database);

                // Set the azure editions (defaults will accept standard Azure account settings)
                ddp.AzureEdition = this.azureEdition;

                if (this.azureSize > 0)
                {
                    ddp.AzureMaxSize = this.azureSize;
                }

                // DENALI CTP3 version and earlier use these arguments
                dacStore.Import(ddp, this.fileName);

                // DAC Versions after Aug 2011 will have these arguments
                // dacStore.Import(this.fileName, ddp);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                sw.Stop();
                Console.WriteLine("Import Complete.  Total time: {0}", sw.Elapsed.ToString());

                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 6
0
        internal void EventSubscribe(DacStore dacStore)
        {
            if (dacStore != null)
            {
                // The finished action is fired after a dac action has completed
                dacStore.DacActionFinished += new EventHandler <DacActionEventArgs>(dacStore_DacActionFinished);

                // The initialized event is fired when a dac action object is allocated (verbose)
                //dacStore.DacActionInitialized += new EventHandler<DacActionEventArgs>(dacStore_DacActionInitialized);

                // The started action is fired before any work has started on the event
                dacStore.DacActionStarted += new EventHandler <DacActionEventArgs>(dacStore_DacActionStarted);
            }
        }
Esempio n. 7
0
        public void DeployAction()
        {
            DacStore dacStore = null;
            Stopwatch sw = new Stopwatch();

            try
            {
                DacType dacType = DacType.Load(File.Open(this.fileName, FileMode.Open));
                Console.WriteLine("Deploy started: {0}", DateTime.Now);

                ServerConnection connection = this.GetServerConnection(null);

                sw.Start();

                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                // Build the deployment properties.
                DatabaseDeploymentProperties ddp = new DatabaseDeploymentProperties(connection, this.database);

                // Set the azure editions (defaults will accept standard Azure account settings)
                ddp.AzureEdition = this.azureEdition;

                if (this.azureSize > 0)
                {
                    ddp.AzureMaxSize = this.azureSize;
                }

                dacStore.Install(dacType, ddp, true);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                sw.Stop();
                Console.WriteLine("Deploy Complete.  Total time: {0}", sw.Elapsed.ToString());

                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 8
0
        public void DeployAction()
        {
            DacStore  dacStore = null;
            Stopwatch sw       = new Stopwatch();

            try
            {
                DacType dacType = DacType.Load(File.Open(this.fileName, FileMode.Open));
                Console.WriteLine("Deploy started: {0}", DateTime.Now);

                ServerConnection connection = this.GetServerConnection(null);

                sw.Start();

                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                // Build the deployment properties.
                DatabaseDeploymentProperties ddp = new DatabaseDeploymentProperties(connection, this.database);

                // Set the azure editions (defaults will accept standard Azure account settings)
                ddp.AzureEdition = this.azureEdition;

                if (this.azureSize > 0)
                {
                    ddp.AzureMaxSize = this.azureSize;
                }

                dacStore.Install(dacType, ddp, true);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                sw.Stop();
                Console.WriteLine("Deploy Complete.  Total time: {0}", sw.Elapsed.ToString());

                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 9
0
        public void ExportAction()
        {
            ServerConnection connection = this.GetServerConnection(this.database);

            DacStore dacStore = null;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Export started: {0}", DateTime.Now);

            try
            {
                sw.Start();

                // Get a DacStore for the current connection
                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                dacStore.Export(this.database, this.fileName);

                sw.Stop();

                FileInfo fi = new FileInfo(this.fileName);

                Console.WriteLine("Export Complete.  Total time: {0}", sw.Elapsed.ToString());
                Console.WriteLine("Output file: {0} Size: {1} bytes", this.fileName, fi.Length);
            }
            catch (BacpacException bacpacex)
            {
                Console.WriteLine("BACPAC Exception: {0}", bacpacex);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 10
0
        public void ExportAction()
        {
            ServerConnection connection = this.GetServerConnection(this.database);

            DacStore dacStore = null;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Export started: {0}", DateTime.Now);

            try
            {
                sw.Start();

                // Get a DacStore for the current connection
                dacStore = new DacStore(connection);

                this.EventSubscribe(dacStore);

                dacStore.Export(this.database, this.fileName);

                sw.Stop();

                FileInfo fi = new FileInfo(this.fileName);

                Console.WriteLine("Export Complete.  Total time: {0}", sw.Elapsed.ToString());
                Console.WriteLine("Output file: {0} Size: {1} bytes", this.fileName, fi.Length);
            }
            catch (BacpacException bacpacex)
            {
                Console.WriteLine("BACPAC Exception: {0}", bacpacex);
            }
            catch (DacException dacex)
            {
                Console.WriteLine("DAC Exception: {0}", dacex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: {0}", ex);
            }
            finally
            {
                this.EventUnsubscribe(dacStore);
            }
        }
Esempio n. 11
0
        public void DropDACAction()
        {
            DacStore dacStore = null;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("Operation started: {0}", DateTime.Now);
            ServerConnection connection = this.GetServerConnection(null);

            try
            {
                dacStore = new DacStore(connection);
                dacStore.Uninstall(this.database, DacUninstallMode.DropDatabase);

                Console.WriteLine("Dac.Uninstall called to remove database and DAC references.");
            }
            catch
            {
                // We ignore all errors at this point - just trying to get rid of the database and any DAC registrations
                Console.WriteLine("[WARNING] DAC.Uninstall failed. DAC Registration may not be present.");

                try
                {
                    // If the database has already been dropped, but the DAC entry still exists we have to unmanage it
                    // Try to unmanage the Data Tier Application entry
                    dacStore.Unmanage(this.database);

                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine("Dac.Unmanage called to remove DAC related history.");
                }
                catch
                {
                    Console.WriteLine("[WARNING] Database does not appear to be registered as a DAC.  DAC.Unmanage failed.");
                }

                try
                {
                    // This won't work on sql azure, so don't even try
                    if (connection.DatabaseEngineType != DatabaseEngineType.SqlAzureDatabase)
                    {
                        // Delete all the backuphistory if we can...
                        StringCollection sqlcommands = new StringCollection();
                        sqlcommands.Add(string.Format("EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'{0}'", this.database));

                        connection.ExecuteNonQuery(sqlcommands, ExecutionTypes.ContinueOnError);

                        Console.WriteLine("Deleted database DAC history.");
                    }
                }
                catch
                {
                    Console.WriteLine("[WARNING] Failed on call sp_delete_database_backuphistory.  Server may not be DAC compatible.");
                }

                try
                {
                    // If there was a database, but it was not DAC managed, we should drop it
                    connection.ExecuteNonQuery(string.Format("DROP DATABASE [{0}]", this.database));

                    Console.WriteLine("Dropped database using SQL.");
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to drop database.  Verify database exists, and you have permissions to drop it.");
                }
            }
            finally
            {
                sw.Stop();
                Console.WriteLine("Operation Complete.  Total time: {0}", sw.Elapsed.ToString());
            }
        }