project.ReplayUserActions
weather99
Posts: 4
I am in the process of testing the capabilities of SQL Comparision SDK. I have a trial version which I think is 10.?.
I am developing in c#, .net 3.5.
I am working with the sample project SQLDataCompareCodeSnippets.
One of the functions I am evaluating is the use of SQL Data Compares to define the tables I want to compare (rather than put the configurations in code).
In this example:
http://documentation.red-gate.com/displ ... ng+the+API
It says "Line 65 shows the method ReplayUserActions, which allows the mappings to be accessed from the project file."
At Line 65 it shows: project.ReplayUserActions(mappings)
When I try to emulate this ProjectExample.cs code sample (copied below), Visual Studio cannot find the ReplayUserActions method on the instance variable project.
Could you tell me what I am missing? Or not understanding?
Code sample:
Project file which contains the list of referenced Assemblies.
I am developing in c#, .net 3.5.
I am working with the sample project SQLDataCompareCodeSnippets.
One of the functions I am evaluating is the use of SQL Data Compares to define the tables I want to compare (rather than put the configurations in code).
In this example:
http://documentation.red-gate.com/displ ... ng+the+API
It says "Line 65 shows the method ReplayUserActions, which allows the mappings to be accessed from the project file."
At Line 65 it shows: project.ReplayUserActions(mappings)
When I try to emulate this ProjectExample.cs code sample (copied below), Visual Studio cannot find the ReplayUserActions method on the instance variable project.
Could you tell me what I am missing? Or not understanding?
Code sample:
using System; using System.IO; using System.Data.SqlClient; using RedGate.Shared.SQL; using RedGate.SQLCompare.Engine; using RedGate.SQLDataCompare.Engine; // commented out because it will not build wit it commented in. //using Project = RedGate.SQLDataCompare.Engine.Project; using RedGate.Shared.SQL.ExecutionBlock; using RedGate.SQLCompare.Engine.ReadFromFolder; using RedGate.SQLDataCompare.Engine.ResultsStore; namespace SQLDataCompareCodeSnippets { public class ProjectExample { private const string projectName = @"MyProject.sdc"; public void RunExample() { Project project=new Project(); project.DataSource1.DatabaseName = Program.DevDatabaseName; project.DataSource2.DatabaseName = Program.LiveDatabaseName; project.SessionSettings = SessionSettings.Default; project.DCOptions = new EngineDataCompareOptions(MappingOptions.Default,ComparisonOptions.Default, SqlOptions.Default); Console.WriteLine("Saving project"); project.SaveToDisk(projectName); //load up the project Project project2=Project.LoadFromDisk(projectName); Console.WriteLine("Project loaded"); //get the two databases using (Database db1= new Database()) using (Database db2 = new Database()) { SchemaMappings mappings = new SchemaMappings(); //Should check if this is true LiveDatabaseSource liveDb1 = project2.DataSource1 as LiveDatabaseSource; liveDb1.ServerName = "db1"; liveDb1.UserName = "user"; liveDb1.Password = "password"; ConnectionProperties sourceConnectionProperties = liveDb1.ToConnectionProperties(); //Should check if this is true LiveDatabaseSource liveDb2 = project2.DataSource2 as LiveDatabaseSource; liveDb2.ServerName = "db2"; liveDb2.UserName = "user"; liveDb2.Password = "password"; ConnectionProperties targetConnectionProperties = liveDb2.ToConnectionProperties(); try { Console.WriteLine("Registering database " + sourceConnectionProperties.DatabaseName); db1.RegisterForDataCompare(sourceConnectionProperties, Options.Default); } catch (SqlException e) { Console.WriteLine(e.Message); Console.WriteLine(@" Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are: o The sample databases are not installed o ServerName not set to the location of the target database o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor o Remote connections not enabled", sourceConnectionProperties.DatabaseName, sourceConnectionProperties.ServerName); return; } try { Console.WriteLine("Registering database " + targetConnectionProperties.DatabaseName); db2.RegisterForDataCompare(targetConnectionProperties, Options.Default); } catch (SqlException e) { Console.WriteLine(e.Message); Console.WriteLine(@" Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are: o The sample databases are not installed o ServerName not set to the location of the target database o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor o Remote connections not enabled", targetConnectionProperties.DatabaseName, targetConnectionProperties.ServerName); return; } mappings.Options = project2.DCOptions; mappings.CreateMappings(db1, db2); /// fails to fine methodReplayUserActions on project1 or project2 object project2.ReplayUserActions(mappings); //Disable any mappings here that you may want.... using (ComparisonSession session = new ComparisonSession()) { session.Options = project2.DCOptions; session.CompareDatabases(db1, db2, mappings); Console.WriteLine("Comparison run"); // now get the ExecutionBlock containing the SQL // we want to run this on WidgetLive so we pass on true as the second parameter SqlProvider provider = new SqlProvider(); // // Also rememeber to set up the provider options // provider.Options = session.Options; try { ExecutionBlock block = provider.GetMigrationSQL(session, true); Console.WriteLine("The synchronization SQL contains {0} lines in {1} batches", block.LineCount, block.BatchCount); // if the ExecutionBlock was very large this could cause memory problems Console.WriteLine("The SQL to be run is:"); Console.WriteLine(block.GetString()); bool needStream = false; if (needStream) { using (Stream stream = block.GetFileStream()) { // we can access the SQL in a memory efficient manner by accessing the underlying stream } } bool executeSql = true; if (executeSql) { Console.WriteLine("Updating target database"); BlockExecutor executor = new BlockExecutor(); executor.ExecuteBlock(block, db2.ConnectionProperties.ToDBConnectionInformation()); } else { Console.WriteLine("Skipping: Updating target database"); } } finally { //Always dispose the SqlProvider's ExecutionBlock because GetMigrationSQL could throw an exception but still set it ExecutionBlock block = provider.Block; if (block != null) block.Dispose(); } } } } } }
Project file which contains the list of referenced Assemblies.
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0"> <PropertyGroup> <ProjectType>Local</ProjectType> <ProductVersion>9.0.30729</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{73FDA88C-A4F8-43B7-AED3-F6A398F55337}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ApplicationIcon>App.ico</ApplicationIcon> <AssemblyKeyContainerName> </AssemblyKeyContainerName> <AssemblyName>SQLDataCompareCodeSnippets</AssemblyName> <AssemblyOriginatorKeyFile> </AssemblyOriginatorKeyFile> <DefaultClientScript>JScript</DefaultClientScript> <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> <DefaultTargetSchema>IE50</DefaultTargetSchema> <DelaySign>false</DelaySign> <OutputType>Exe</OutputType> <RootNamespace>SQLDataCompareCodeSnippets</RootNamespace> <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> <StartupObject> </StartupObject> <FileUpgradeFlags> </FileUpgradeFlags> <UpgradeBackupLocation> </UpgradeBackupLocation> <OldToolsVersion>3.5</OldToolsVersion> <IsWebBootstrapper>false</IsWebBootstrapper> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <PublishUrl>publish</PublishUrl> <Install>true</Install> <InstallFrom>Disk</InstallFrom> <UpdateEnabled>false</UpdateEnabled> <UpdateMode>Foreground</UpdateMode> <UpdateInterval>7</UpdateInterval> <UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdatePeriodically>false</UpdatePeriodically> <UpdateRequired>false</UpdateRequired> <MapFileExtensions>true</MapFileExtensions> <ApplicationRevision>0</ApplicationRevision> <ApplicationVersion>1.0.0.%2a</ApplicationVersion> <UseApplicationTrust>false</UseApplicationTrust> <BootstrapperEnabled>true</BootstrapperEnabled> <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <OutputPath>binDebug</OutputPath> <AllowUnsafeBlocks>false</AllowUnsafeBlocks> <BaseAddress>285212672</BaseAddress> <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> <ConfigurationOverrideFile> </ConfigurationOverrideFile> <DefineConstants>DEBUG;TRACE</DefineConstants> <DocumentationFile> </DocumentationFile> <DebugSymbols>true</DebugSymbols> <FileAlignment>4096</FileAlignment> <NoStdLib>false</NoStdLib> <NoWarn> </NoWarn> <Optimize>false</Optimize> <RegisterForComInterop>false</RegisterForComInterop> <RemoveIntegerChecks>false</RemoveIntegerChecks> <TreatWarningsAsErrors>false</TreatWarningsAsErrors> <WarningLevel>4</WarningLevel> <DebugType>full</DebugType> <ErrorReport>prompt</ErrorReport> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <OutputPath>binRelease</OutputPath> <AllowUnsafeBlocks>false</AllowUnsafeBlocks> <BaseAddress>285212672</BaseAddress> <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> <ConfigurationOverrideFile> </ConfigurationOverrideFile> <DefineConstants>TRACE</DefineConstants> <DocumentationFile> </DocumentationFile> <DebugSymbols>false</DebugSymbols> <FileAlignment>4096</FileAlignment> <NoStdLib>false</NoStdLib> <NoWarn> </NoWarn> <Optimize>true</Optimize> <RegisterForComInterop>false</RegisterForComInterop> <RemoveIntegerChecks>false</RemoveIntegerChecks> <TreatWarningsAsErrors>false</TreatWarningsAsErrors> <WarningLevel>4</WarningLevel> <DebugType>none</DebugType> <ErrorReport>prompt</ErrorReport> </PropertyGroup> <ItemGroup> <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareNewtonsoft.Json.dll</HintPath> </Reference> <Reference Include="RedGate.BackupReader"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.BackupReader.dll</HintPath> </Reference> <Reference Include="RedGate.BackupReader.SqbReader"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.BackupReader.SqbReader.dll</HintPath> </Reference> <Reference Include="RedGate.Migrations.Core"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.Migrations.Core.dll</HintPath> </Reference> <Reference Include="RedGate.Shared.ComparisonInterfaces"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.Shared.ComparisonInterfaces.dll</HintPath> </Reference> <Reference Include="RedGate.Shared.SQL, Version=7.1.0.39, Culture=neutral, PublicKeyToken=7f465a1c156d4d57, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.Shared.SQL.dll</HintPath> </Reference> <Reference Include="RedGate.Shared.Utils, Version=7.1.0.39, Culture=neutral, PublicKeyToken=7f465a1c156d4d57, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.Shared.Utils.dll</HintPath> </Reference> <Reference Include="RedGate.SOCCompareInterface"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.SOCCompareInterface.dll</HintPath> </Reference> <Reference Include="RedGate.SQLCompare.ASTParser"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.SQLCompare.ASTParser.dll</HintPath> </Reference> <Reference Include="RedGate.SQLCompare.Engine, Version=7.1.0.182, Culture=neutral, PublicKeyToken=7f465a1c156d4d57, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.SQLCompare.Engine.dll</HintPath> </Reference> <Reference Include="RedGate.SQLCompare.Rewriter"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.SQLCompare.Rewriter.dll</HintPath> </Reference> <Reference Include="RedGate.SQLDataCompare.Engine, Version=7.1.0.230, Culture=neutral, PublicKeyToken=7f465a1c156d4d57, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareRedGate.SQLDataCompare.Engine.dll</HintPath> </Reference> <Reference Include="System"> <Name>System</Name> </Reference> <Reference Include="System.Data"> <Name>System.Data</Name> </Reference> <Reference Include="System.Data.SQLite"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareSystem.Data.SQLite.dll</HintPath> </Reference> <Reference Include="System.Drawing"> <Name>System.Drawing</Name> </Reference> <Reference Include="System.Threading"> <HintPath>........Program Files (x86)Red GateSQL Comparison SDK 10AssembliesSQL Data CompareSystem.Threading.dll</HintPath> </Reference> <Reference Include="System.Windows.Forms"> <Name>System.Windows.Forms</Name> </Reference> <Reference Include="System.Xml"> <Name>System.XML</Name> </Reference> </ItemGroup> <ItemGroup> <Content Include="App.ico" /> <Compile Include="BackupComparisonExample.cs" /> <Compile Include="BackupExample.cs" /> <Compile Include="BackupSetExample.cs" /> <Compile Include="BlobExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="ComparisonSessionExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="ComparisonSessionWithProgressExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="FilterSQLExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Program.cs"> <SubType>Code</SubType> </Compile> <Compile Include="ProjectExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="PropertiesAssemblyInfo.cs" /> <Compile Include="SqlProviderExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="StoreExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="TableMappingExample.cs"> <SubType>Code</SubType> </Compile> <Compile Include="WhereExample.cs"> <SubType>Code</SubType> </Compile> <Content Include="UserProfileandstgpbdb2.sdc" /> </ItemGroup> <ItemGroup> <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> <Install>false</Install> </BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> <Visible>False</Visible> <ProductName>.NET Framework 2.0 %28x86%29</ProductName> <Install>true</Install> </BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Framework.3.0"> <Visible>False</Visible> <ProductName>.NET Framework 3.0 %28x86%29</ProductName> <Install>false</Install> </BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5"> <Visible>False</Visible> <ProductName>.NET Framework 3.5</ProductName> <Install>false</Install> </BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1</ProductName> <Install>false</Install> </BootstrapperPackage> </ItemGroup> <ItemGroup> <None Include="..BackupFilesWidgetDev.bak"> <Link>WidgetDev.bak</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="app.config" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="licenses.licx" /> </ItemGroup> <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" /> <PropertyGroup> <PreBuildEvent> </PreBuildEvent> <PostBuildEvent> </PostBuildEvent> </PropertyGroup> </Project>
Comments
I think this is a feature that is in a branch of our code but has not yet been released(!)
let me do some further investigations...
I also use the method "ReplayUserActions" in my project.
It is located in the namespace "SQLDataCompare.Engine.DataCompareUserActions".
I think the example has not been updated yet.
Kind regards,
bmolsbeck.
Thank you for your suggestion!
I will try the REplayUserActions method in SQLDAtaCompare.Engine.DAtaCompareUserActions.
I can see where I can set the table actions and data sources from the arguments.
How to do get it to do this from actions and data sources I specified in the Project file I saved with SQL Data Compare (i.e. sdc file)?
In my previous post I listed the code I am working with ... I am calling this method: Project project2=Project.LoadFromDisk(projectName);
from the ProjectExample.cs file ... the generation of the SQL to do the update ... includes tables which are not included in the SDC file.
What do you think?