Red Gate forums :: View topic - Update, Insert but not Delete
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

Update, Insert but not Delete

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
ryolatl@hotmail.com



Joined: 30 Aug 2011
Posts: 3

PostPosted: Wed Aug 31, 2011 5:03 pm    Post subject: Update, Insert but not Delete Reply with quote

I compare two database.

DB Source and DB Target,

what I'm doing is Insert or Update the records that from the DB Source to the DB Target but at some point the DB Source is going to be deleted.

With the Code that I have now If I do this, all the DB Target is deleted as well and I don't want this.

What I need is to be able to Insert, Update but not Delete, Could you point me in the right direction?

thanks

this is the code that I'm using for the Execution.

Dim provider As New SqlProvider
Dim block As ExecutionBlock
Try
block = provider.GetMigrationSQL(session, True)
provider.Options.SqlOptions.

txtResults.Text += "The synchronization SQL contains " & block.LineCount & " lines in " & block.BatchCount & " batches"

txtResults.Text += "The SQL to be run is:"
txtResults.Text += block.GetString()


Dim needStream As Boolean = True
If needStream Then
Using stream As Stream = block.GetFileStream
'we can access the SQL in a memory efficient manner by accessing the underlying stream
End Using
End If

Dim executeSql As Boolean = True
If executeSql Then
txtResults.Text += "Updating target database"
Dim executor As New BlockExecutor()
executor.ExecuteBlock(block, "10.202.1.111", "Sync_target", False, "user", "pass")
Else
txtResults.Text += "Skipping: Updating target database"
End If

Finally
block = provider.Block
If (TypeOf block Is ExecutionBlock) Then
block.Dispose()
End If
session.Dispose()
db1.Dispose()
db2.Dispose()
End Try
Back to top
View user's profile Send private message
Chris Auckland



Joined: 24 Oct 2006
Posts: 755
Location: Red Gate Software Ltd.

PostPosted: Fri Sep 02, 2011 11:37 am    Post subject: Reply with quote

Thanks for your post.

I think I would probably use a selection delegate with GetMigration()

e.g.
Code:
block = provider.GetMigrationSQL(session, new SelectionDelegate(this.ExDelete), true);


With a method to loop through the results store and deselect all the deletes, e.g.


Code:
protected bool ExDelete(SynchronizationRecord syncRecordObject)
        {
            Reader resultsReader = m_TableDifferences[syncRecordObject.TableName].ResultsStore.GetReader(Row.RowType.All);

                Row myRow = resultsReader.GetRow(syncRecordObject.Bookmark);

                // if the row is only in the target database, deselect from sync.
                if (myRow.Type == Row.RowType.In2)
                {
                    return false;
                }

            return true;
        }


I hope this helps point you in the right direction.
_________________
Chris
Back to top
View user's profile Send private message Send e-mail
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