Re: Using a Project object
Brian Donahue
Posts: 6,590 Bronze 1
Hi,
Actually, the Toolkit help file is wrong. Project files don't populate the
database objects or a few other properties that need to be dropped and the
Compare() method is obsolete.
The only things in the sdc file appear to be database connection properties
and object and settings selections.
Here is some VB example code for handling a Data Compare project file:
Function Main
Dim sDataMigrationSQL As String
Dim obSqlProvider1 As SqlProvider = New SqlProvider()
Dim dbSourceDatabase As Database
Dim dbTargetDatabase As Database
Dim obTableComparisonSettings As TableComparisonSettings = New
TableComparisonSettings()
Dim obComparisonSession As ComparisonSession = New ComparisonSession()
Dim obExeBlock As ExecutionBlock
Dim p As Project
P= Project.LoadFromDisk("NewProject.sdc", true)
dbSourceDatabase = obSqlProvider1.GetDatabase(p.ConnectionProperties1)
dbTargetDatabase = obSqlProvider1.GetDatabase(p.ConnectionProperties2)
obComparisonSession.CompareDatabases(dbSourceDatabase, dbTargetDatabase,
p.TableComparisonSettings)
obExeBlock = obSqlProvider1.GetMigrationSQL(obComparisonSession,
false)
sDataMigrationSQL = obExeBlock.ToString()
Console.WriteLine(sDataMigrationSQL)
End Function
Regards,
Brian Donahue
Red Gate Technical Support
"Brian Donahue (Red Gate)" wrote in cWfB$dmbEHA.1184@server53:
>Hi Paul,
>
> Thanks for writing. The example is designed to be self-contained: it
>shows how to set up a data comparison, save the settings to a file, and load
>the file from disk again.
>
> You can load a project file into a Project object at any time with the
>LoadFromDisk method, then you can use those settings through the Compare
>method of the Project object:
>
>Project project2=Project.LoadFromDisk(@c: estproject.sdc, true);
>
>Console.WriteLine("Project loaded");
>
>//compare it
>project2.Compare();
>
>Console.WriteLine("Comparison run");
>
>//dispose of the ComparisonSession
>project2.ComparisonSession.Dispose();
>
>Regards,
>
>
>
>Brian Donahue
>
>Red Gate Technical Support
>
>
>"Paul Buxton" <psb@NOSPAMspireite.demon.co.uk> wrote in message
>news:1s0ug9b85bof1.1xgu76m65u8ax.dlg@40tude.net...
>>
>> The sample SqlDataCompareCodeSnippets is confusing.
>>
>> What do I need to actually do in initialisation before creating a Project
>> object, and loading the SDC?
>>
>> The sample, already sets stuff up before saving the project and
>immediately
>> reloading it.
>>
>> Can you see where I'm confused?
>>
>> Thx
>>
>>
>>
>>
>
>
>
Actually, the Toolkit help file is wrong. Project files don't populate the
database objects or a few other properties that need to be dropped and the
Compare() method is obsolete.
The only things in the sdc file appear to be database connection properties
and object and settings selections.
Here is some VB example code for handling a Data Compare project file:
Function Main
Dim sDataMigrationSQL As String
Dim obSqlProvider1 As SqlProvider = New SqlProvider()
Dim dbSourceDatabase As Database
Dim dbTargetDatabase As Database
Dim obTableComparisonSettings As TableComparisonSettings = New
TableComparisonSettings()
Dim obComparisonSession As ComparisonSession = New ComparisonSession()
Dim obExeBlock As ExecutionBlock
Dim p As Project
P= Project.LoadFromDisk("NewProject.sdc", true)
dbSourceDatabase = obSqlProvider1.GetDatabase(p.ConnectionProperties1)
dbTargetDatabase = obSqlProvider1.GetDatabase(p.ConnectionProperties2)
obComparisonSession.CompareDatabases(dbSourceDatabase, dbTargetDatabase,
p.TableComparisonSettings)
obExeBlock = obSqlProvider1.GetMigrationSQL(obComparisonSession,
false)
sDataMigrationSQL = obExeBlock.ToString()
Console.WriteLine(sDataMigrationSQL)
End Function
Regards,
Brian Donahue
Red Gate Technical Support
"Brian Donahue (Red Gate)" wrote in cWfB$dmbEHA.1184@server53:
>Hi Paul,
>
> Thanks for writing. The example is designed to be self-contained: it
>shows how to set up a data comparison, save the settings to a file, and load
>the file from disk again.
>
> You can load a project file into a Project object at any time with the
>LoadFromDisk method, then you can use those settings through the Compare
>method of the Project object:
>
>Project project2=Project.LoadFromDisk(@c: estproject.sdc, true);
>
>Console.WriteLine("Project loaded");
>
>//compare it
>project2.Compare();
>
>Console.WriteLine("Comparison run");
>
>//dispose of the ComparisonSession
>project2.ComparisonSession.Dispose();
>
>Regards,
>
>
>
>Brian Donahue
>
>Red Gate Technical Support
>
>
>"Paul Buxton" <psb@NOSPAMspireite.demon.co.uk> wrote in message
>news:1s0ug9b85bof1.1xgu76m65u8ax.dlg@40tude.net...
>>
>> The sample SqlDataCompareCodeSnippets is confusing.
>>
>> What do I need to actually do in initialisation before creating a Project
>> object, and loading the SDC?
>>
>> The sample, already sets stuff up before saving the project and
>immediately
>> reloading it.
>>
>> Can you see where I'm confused?
>>
>> Thx
>>
>>
>>
>>
>
>
>
This discussion has been closed.