Updating databases - foreign keys problem
TheBatA
Posts: 18
Hi!
I have the following problem with SQL toolkit 6:
I have one database that needs to be updated. Almost all tables are related and have foreign keys.
I need to update some of those tables, not all of them. In another database I have tables with updated data (full tables, not just different rows).
In one datagrid I have list of tables and chechboxes that are used to select tables to update.
If I select only those tables I want to update, I get correct data for update, but when I create a package using SQL Packager, I get an error
"The DELETE statement conflicted with the REFERENCE constraint " and table on which error occured isn't in list for data compare (at least I didn't selected it).
I use following code for selecting data for compare:
How could I solve this?
I have the following problem with SQL toolkit 6:
I have one database that needs to be updated. Almost all tables are related and have foreign keys.
I need to update some of those tables, not all of them. In another database I have tables with updated data (full tables, not just different rows).
In one datagrid I have list of tables and chechboxes that are used to select tables to update.
If I select only those tables I want to update, I get correct data for update, but when I create a package using SQL Packager, I get an error
"The DELETE statement conflicted with the REFERENCE constraint " and table on which error occured isn't in list for data compare (at least I didn't selected it).
I use following code for selecting data for compare:
db1.RegisterForDataCompare(new ConnectionProperties(cbSrvSrc.Text, cbDbSrc.Text)); db2.RegisterForDataCompare(new ConnectionProperties(cbSrvDest.Text, cbDbDest.Text)); TableMappings mappings = new TableMappings(); foreach (DataGridViewRow dgr in dgvTabele.Rows) { if ((bool)dgr.Cells[1].Value == true) { TableMapping tableMapping = (TableMapping)mappings.Join(db1.Tables[dgr.Cells[0].Value.ToString()], db2.Tables[dgr.Cells[0].Value.ToString()]); tableMapping.Where = new WhereClause(dgr.Cells[2].Value.ToString()); mappings.Add(tableMapping); } } session = new ComparisonSession(); session.CompareDatabases(db1, db2, mappings); ... schemaMappings = new SchemaMappings(); schemaMappings.CreateMappings(db1, db2); ‚ SqlProvider provider = new SqlProvider(); try { provider.GetMigrationSQL(session, true); } finally { dataBlock = provider.Block; }
How could I solve this?
Comments
Give that a go and hopefully it'll work a little better for you.
HTH
Project Manager
Red Gate Software Ltd
but I still get the same result.
Is this correct syntax for excluding tables from data compare?
I tried a lot of ways solving problem, but I still get the same result.
to disable foreign keys.
Project Manager
Red Gate Software Ltd
I get the same result!
Where should I call GenerateSQL? I don't see that option in provider.
I also tried to add
Can I somehow compare all the tables and then save list of constraints to be dropped form a session or schemamappings? Can I add this list in list of constraints in new session/schemamapping which would contain only tables I need?
Can anybody describe how this stuff with constraints work in SQL Toolkit?
I've just run a test internally about disabling foreign keys and it seems to work for not-included tables (i.e. if you choose to synchronize a table and another table has a foreign key reference to it we will disable that foreign key even though you're not synchronzing that table). Although the tables have to be in the comparison and then excluded from the synchronization - I suppose a little trick so that they don't actually compare any data would be to set a WHERE clause on those tables such that they will return no rows (e.g. 1=2) :twisted: .
DisableKeys in the important option - I got confuddled with our options.
HTH
Project Manager
Red Gate Software Ltd
That's good timing, I was just investigating and preparing my reply then
Project Manager
Red Gate Software Ltd
Error wasn't in packager, it was this error I got in application that was created by packager, about constraints.
Well, I know that there is a proof that 1 is equal to 2 (for extremely large values of 1 ), but fortunatelly it's not the case here!
Thanks for help!
Regards,
Jagadeeswaran AC
I hope this works for you.