Red Gate forums :: View topic - Deactivating IncludeDependencies Still Includes CREATE USER
Return to RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Packager 6
SQL Packager 6 forum

Deactivating IncludeDependencies Still Includes CREATE USER

Search in SQL Packager 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message

Joined: 30 Sep 2011
Posts: 2

PostPosted: Fri Sep 30, 2011 7:27 pm    Post subject: Deactivating IncludeDependencies Still Includes CREATE USER Reply with quote

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));

Back to top
View user's profile Send private message
Brian Donahue

Joined: 23 Aug 2004
Posts: 6678

PostPosted: Mon Oct 03, 2011 11:36 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message

Joined: 30 Sep 2011
Posts: 2

PostPosted: Mon Oct 03, 2011 5:36 pm    Post subject: Reply with quote

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

Thanks for the reply, Brian!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group