public void ExtractDacpac(string filePath, IEnumerable<Tuple<string, string>> tables = null, DacExtractOptions extractOptions = null) { DacServices ds = new DacServices(this.BuildConnectionString()); ds.Extract(filePath, this.DatabaseName, this.DatabaseName, new Version(1, 0, 0), string.Empty, tables, extractOptions); }
public override void Execute() { Version version = ParseVersion(this.Parameters.ApplicationVersion); DacExtractOptions extractOptions = GetExtractOptions(this.Parameters.ExtractTarget); this.DacServices.Extract(this.Parameters.PackageFilePath, this.Parameters.DatabaseName, this.Parameters.ApplicationName, version, applicationDescription: null, tables: null, extractOptions: extractOptions, cancellationToken: this.CancellationToken); }
private static DacPackage Extract(string serverName, string databaseName, FileInfo packageFile, string label) { SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder { DataSource = serverName, InitialCatalog = databaseName, IntegratedSecurity = true }; DacServices dacServices = new DacServices(connectionStringBuilder.ConnectionString); dacServices.ProgressChanged += (s, e) => { if (e.Status == DacOperationStatus.Running) { Console.WriteLine("{0} ({1})", e.Message, label); } }; DacExtractOptions extractOptions = new DacExtractOptions { IgnorePermissions = false, IgnoreUserLoginMappings = true, Storage = DacSchemaModelStorageType.Memory }; // Ensure the package file directory exists. packageFile.Directory.Create(); dacServices.Extract(packageFile.FullName, databaseName, databaseName, new Version(1, 0), extractOptions: extractOptions); return(DacPackage.Load(packageFile.FullName, DacSchemaModelStorageType.Memory)); }
private DacExtractOptions GetExtractOptions(DacExtractTarget extractTarget) { DacExtractOptions extractOptions = new DacExtractOptions() { ExtractTarget = extractTarget }; return(extractOptions); }
public static bool Export(string sourceDbConString, string outDacFilePath) { bool result = false; var sourceConBuilder = new SqlConnectionStringBuilder(sourceDbConString); var services = new DacServices(sourceConBuilder.ConnectionString); services.ProgressChanged += ((s, e) => { Console.WriteLine("Ëxporting Dacpack Status:{0} , Message:{1}.", e.Status, e.Message); }); string blobName; if (System.IO.File.Exists(outDacFilePath)) { System.IO.File.Delete(outDacFilePath); } using (FileStream stream = File.Open(outDacFilePath, FileMode.Create, FileAccess.ReadWrite)) { Console.WriteLine("starting bacpac export"); DacExportOptions opts = new DacExportOptions() { TargetEngineVersion = EngineVersion.Default, Storage = DacSchemaModelStorageType.Memory, VerifyFullTextDocumentTypesSupported = false }; var extOptions = new DacExtractOptions() { ExtractAllTableData = false, ExtractApplicationScopedObjectsOnly = true, ExtractReferencedServerScopedElements = true }; services.Extract(packageStream: stream, databaseName: sourceConBuilder.InitialCatalog, applicationName: "Schema_Exporter", extractOptions: extOptions, applicationVersion: Version.Parse("1.0.0.0")); stream.Flush(); return(true); } return(result); }
public static bool ExtractDacPac(string sourceDatabase, string sourceServer, AuthenticationType authType, string userName, string password, string dacPacFileName) { try { log.LogInformation($"Extracting dacpac from {sourceServer} : {sourceDatabase}"); DacExtractOptions opts = new DacExtractOptions(); opts.IgnoreExtendedProperties = true; opts.IgnoreUserLoginMappings = true; SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(); if (authType == AuthenticationType.Windows) { connBuilder.IntegratedSecurity = true; } if (!string.IsNullOrWhiteSpace(userName)) { connBuilder.UserID = userName; } if (!string.IsNullOrWhiteSpace(password)) { connBuilder.Password = password; } connBuilder.DataSource = sourceServer; connBuilder.InitialCatalog = sourceDatabase; Version ver = Assembly.GetExecutingAssembly().GetName().Version; DacServices service = new DacServices(connBuilder.ConnectionString); service.Extract(dacPacFileName, sourceDatabase, "Sql Build Manager", ver); log.LogInformation($"dacpac from {sourceServer}.{sourceDatabase} saved to {dacPacFileName}"); return(true); } catch (Exception exe) { log.LogError($"Problem creating DACPAC from {sourceServer}.{sourceDatabase}: {exe.ToString()}"); return(false); } }
public bool TryExtractDacpac(string filePath, out string error, IEnumerable<Tuple<string, string>> tables = null, DacExtractOptions extractOptions = null) { error = null; try { ExtractDacpac(filePath, tables, extractOptions); return true; } catch (Exception ex) { error = ex.Message; return false; } }
public bool TryExtractDacpac(string filePath, out string error, IEnumerable <Tuple <string, string> > tables = null, DacExtractOptions extractOptions = null) { error = null; try { ExtractDacpac(filePath, tables, extractOptions); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
public void ExtractDacpac(string filePath, IEnumerable <Tuple <string, string> > tables = null, DacExtractOptions extractOptions = null) { DacServices ds = new DacServices(this.BuildConnectionString()); ds.Extract(filePath, this.DatabaseName, this.DatabaseName, new Version(1, 0, 0), string.Empty, tables, extractOptions); }
private void Extract(DacServices svc, string SourceDatabaseName, string Path) { Console.WriteLine("\n\rPerforming Extract of {0} to {1} at {2}", SourceDatabaseName, Path, System.DateTime.Now.ToLongTimeString()); DacExtractOptions dacExtractOptions = new DacExtractOptions { ExtractApplicationScopedObjectsOnly = true, ExtractReferencedServerScopedElements = false, VerifyExtraction = true, Storage = DacSchemaModelStorageType.Memory }; svc.Extract(Path, SourceDatabaseName, "Sample DACPAC", new Version(1, 0, 0), "Sample Extract", null, dacExtractOptions); }