Ejemplo n.º 1
0
 public void Build(string dacpacPath, string packageName, IEnumerable <string> scripts)
 {
     using (var model = new TSqlModel(SqlServerVersion.Sql110, new TSqlModelOptions {
     })) {
         // Adding objects to the model.
         foreach (string script in scripts)
         {
             model.AddObjects(script);
         }
         try {
             // save the model to a new .dacpac
             // Note that the PackageOptions can be used to specify RefactorLog and contributors to include
             DacPackageExtensions.BuildPackage(dacpacPath, model,
                                               new PackageMetadata {
                 Name = packageName, Description = string.Empty, Version = "1.0"
             },
                                               new PackageOptions());
             var message = Environment.NewLine +
                           string.Format(CultureInfo.InvariantCulture, Resources.SqlPublish_PublishDacpacSuccess, dacpacPath) +
                           Environment.NewLine;
             _outputWindow.WriteAsync(MessageCategory.General, message).DoNotWait();
         } catch (DacServicesException ex) {
             var error = Environment.NewLine +
                         string.Format(CultureInfo.InvariantCulture, Resources.SqlPublishDialog_UnableToBuildDacPac, ex.Message) +
                         Environment.NewLine;
             _outputWindow.WriteAsync(MessageCategory.Error, error).DoNotWait();
             // _coreShell.ShowErrorMessage(error);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Packages stored procedures into a DACPAC and then publishes it to the database.
        /// </summary>
        private void PublishToDatabase(SqlSProcPublishSettings settings, IEnumerable <string> sprocFiles)
        {
            var dacpacPath = Path.ChangeExtension(Path.GetTempFileName(), DacPacExtension);

            CreateDacPac(settings, sprocFiles, dacpacPath);
            using (var package = _dacServices.Load(dacpacPath)) {
                var dbName     = settings.TargetDatabaseConnection.GetValue(ConnectionStringConverter.OdbcDatabaseKey);
                var connection = settings.TargetDatabaseConnection.OdbcToSqlClient();
                package.Deploy(connection, dbName);

                var message = Environment.NewLine +
                              string.Format(CultureInfo.InvariantCulture, Resources.SqlPublish_PublishDatabaseSuccess, connection) +
                              Environment.NewLine;
                _outputWindow.WriteAsync(MessageCategory.General, message).DoNotWait();
                RtvsTelemetry.Current?.TelemetryService.ReportEvent(TelemetryArea.SQL, SqlTelemetryEvents.SqlDatabasePublish);
            }
        }