Deactivating IncludeDependencies Still Includes CREATE USER

Forum for users of SQL Packager database archive utility

Deactivating IncludeDependencies Still Includes CREATE USER

Postby bsoddy » Fri Sep 30, 2011 6:27 pm

I've run into a peculiar problem with our publishing functionality, which utilizes SQL Compare against a null database in conjunction with SQL Packager to generate a stored executable. The executable acts as a snapshot of the database and is used for restorative purposes.

Even with the IncludeDependencies Option deactivated, I'm still finding that the generated executable contains CREATE USER statements, which can cause issues when restoring a publish.

Included is a scrubbed version of the executing code:

using (Database oDatabase = new Database())
using (ComparisonSession oSession = new ComparisonSession())
SqlProvider oProvider = null;
TableMappings oMappings = new TableMappings();
TableMappings oNewMappings = new TableMappings();
Options oOptions = Options.IgnoreFileGroups |
Options.IgnoreFillFactor |
Options.IgnoreWhiteSpace |
Options.IgnoreWithElementOrder |

// Register the database for schema and data comparison
oDatabase.RegisterForDataCompare(oConnectionProperties, oOptions);
oDatabase.Register(oConnectionProperties, oOptions);

// Build the schema ExecutionBlock
Differences oDifferences = oDatabase.CompareWith(null, oOptions);
foreach (Difference oDifference in oDifferences)
oDifference.Selected = true;
Work oWork = new Work();
oWork.BuildFromDifferences(oDifferences, oOptions, true);

// Since we're packaging up a single database, set the following flag
oMappings.Options.MappingOptions |= MappingOptions.MissingFrom2AsInclude;
oMappings.Options.MappingOptions |= MappingOptions.IgnoreCase;

// Create the mappings
oMappings.CreateMappings(oDatabase.Tables, null);
oNewMappings = oMappings;

oSession.Options = oNewMappings.Options;

m_oRedGateFormProgress = new FormRedGateProgress();
BackgroundWorker worker = new BackgroundWorker();

worker.WorkerReportsProgress = true;
worker.DoWork += delegate
oSession.CompareDatabases(oDatabase, null, oNewMappings);

worker.RunWorkerCompleted += delegate

m_oRedGateFormProgress.SetText("Comparing databases");
m_oRedGateFormProgress.Load += delegate

oSession.Status += new StatusEventHandler(RedGateStatusCallback);


oSession.Status -= new StatusEventHandler(RedGateStatusCallback);

// Create a sql provider to get the insert SQL
oProvider = new SqlProvider();
oProvider.Options = oNewMappings.Options;

// Package the database to a temp local directory
using (ExecutionBlock oDataBlock = oProvider.GetMigrationSQL(oSession, true))
using (PackagerEngine oPackagerEngine = new PackagerEngine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\\Template",
oPackagerEngine.AddProperty("PACKAGE_UPGRADE_DATABASE", Convert.ToString(true));

Posts: 2
Joined: Fri Sep 30, 2011 6:17 pm

Postby Brian Donahue » Mon Oct 03, 2011 10:36 am

I don't see anything in the code that's specifically excluding users from the set of selected differences. You may want to add that condition in the bit where you run through all of the differences and select them.
Brian Donahue
Posts: 6590
Joined: Mon Aug 23, 2004 9:48 am

Postby bsoddy » Mon Oct 03, 2011 4:36 pm

Ah, updating the Difference.Selected portion for DatabaseObjectType.User resolved this.

Thanks for the reply, Brian!
Posts: 2
Joined: Fri Sep 30, 2011 6:17 pm

Return to SQL Packager Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests