I am trying to deploy a .dacpac which was generated from a SQL connection string into a SQL server 2017 ubuntu docker container for integration testing.
I am using the DacFx NuGet package from Microsoft to generate the .dacpac. I tried to find options to ignore the Filegroup but couldn't find any.
Localhost SQL Server Extract Connection String:
Server=localhost;Database=MyDatabase;Integrated Security=true
What I want to achieve: Get the schema from localhost, without any FILEGROUPS or dependent .mdf file into a dacpac, and apply it to a SQL docker container, without having to mount volumes in docker, as I want everything to be kept in ram memory and when the docker container stops the data is gone. Previously I had successfully generated the dacpac and applied it to the docker instance.. when there was no FILEGROUP localhost DB. Also found IgnoreFilegroupPlacement option forDacDeployOptions objbut for some reason, it does not work.
Code:
I am passing the following options to the extract method:
DacServices dacServices = new(targetDacpacDbExtract.ConnectionString);
DacExtractOptions extractOptions = new()
{
ExtractTarget = DacExtractTarget.DacPac,
IgnorePermissions = true,
IgnoreUserLoginMappings = true,
ExtractAllTableData = false,
Storage = DacSchemaModelStorageType.Memory
};
using MemoryStream stream = new();
dacServices.Extract(stream,
targetDacpacDbExtract.DbName,
"MyDatabase",
new Version(1, 0, 0),
extractOptions: extractOptions);
stream.Seek(0, SeekOrigin.Begin);
byte[] dacpacStream = stream.ToArray();
this.logger.LogInformation("Finished extracting schema.");
These are the options that I am passing to the deploy method which extracts the dacpac from the connection string:
SQLConnectionStringDocker:Server=127.0.0.1, 47782;Integrated Security=false;User ID=sa;Password=$Trong12!;
this.logger.LogInformation("Starting Deploy extracted dacpac to Docker SQL container.");
DacDeployOptions options = new()
{
AllowIncompatiblePlatform = true,
CreateNewDatabase = false,
ExcludeObjectTypes = new ObjectType[]
{
ObjectType.Permissions,
ObjectType.RoleMembership,
ObjectType.Logins,
},
IgnorePermissions = true,
DropObjectsNotInSource = false,
IgnoreUserSettingsObjects = true,
IgnoreLoginSids = true,
IgnoreRoleMembership = true,
PopulateFilesOnFileGroups = false,
IgnoreFilegroupPlacement = true
};
DacServices dacService = new(targetDeployDb.ConnectionStringDocker);
using Stream dacpacStream = new MemoryStream(dacBuffer);
using DacPackage dacPackage = DacPackage.Load(dacpacStream);
var deployScript = dacService.GenerateDeployScript(dacPackage, "Kf", options);
dacService.Deploy(
dacPackage,
targetDeployDb.DbName,
upgradeExisting: true,
options);
this.logger.LogInformation("Finished deploying dacpac.");
return Task.CompletedTask;
Error: And this is the error I am receiving from SQL docker container:
If I could ignore the filegroup at all would be awesome because I don't need it.
Could not deploy package.
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5121, Level 16, State 2, Line 1 The path specified by "MyDatabase.CacheItem_FG_195A905.mdf" is not in a valid directory.
Error SQL72045: Script execution error. The executed script:
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [CacheItem_FG_195A905], FILENAME = N'$(DefaultDataPath)$(DefaultFilePrefix)_CacheItem_FG_195A905.mdf') TO FILEGROUP [CacheItem_FG];
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5009, Level 16, State 14, Line 1 One or more files listed in the statement could not be found or could not be initialized.
Error SQL72045: Script execution error. The executed script:
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [CacheItem_FG_195A905], FILENAME = N'$(DefaultDataPath)$(DefaultFilePrefix)_CacheItem_FG_195A905.mdf') TO FILEGROUP [CacheItem_FG];