Get my Web service to read set Tables and db from config
danjaman
Posts: 12
I want to be aboe to set my Datasource (DB) to read from my Web.config file as Connection strings.
I want to also be able to pass a webthod of parameter, be selecting a group that contains a set number of tables from my db.
This way we can set migration to run only on that group og tables. See my Web Service below:
using System;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Xsl;
using System.Text;
using System.Reflection;
using System.Diagnostics; // for ProcessStartInfo
using RedGate.SQL.Shared;
using RedGate.SQLCompare.Engine;
using RedGate.SQLDataCompare.Engine;
namespace SQLDataCompareWebService
{
public struct ClientData
{
public String Name;
public int ID;
}
/// <summary>
/// Summary description for WebService1.
/// </summary>
[WebService(Namespace = "http://localhost/SQLCompareWebService/",
Description="This is a schema/data WebService.")]
public class SQLCompareWebService1 : System.Web.Services.WebService
{
private const int CacheTime = 1000000; // seconds
public SQLCompareWebService1()
{
//CODEGEN: This call is required by the ASP+ Web Services Designer
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
//To build, uncomment the following lines then save and build the project
//
[WebMethod]
public void DataMigration()
{
Database db1 = new Database();
Database db2 = new Database();
try
{
db1.Register(new ConnectionProperties("nse-develop22", "WidgetDev"), Options.Default);
db2.Register(new ConnectionProperties("nse-develop22", "WidgetLive"), Options.Default);
}
catch (System.Data.SqlClient.SqlException sqe)
{
Console.WriteLine("SQL Exception: " + sqe.Message);
return;
}
Differences diffs = db1.CompareWith(db2, Options.Default);
Work w = new Work();
w.BuildFromDifferences(diffs, Options.Default, true);
//Uncomment next line to get schema migration script
string schemaSQL=w.ExecutionBlock.GetString();
//Uncomment the next lines to run migration script
BlockExecutor be=new BlockExecutor();
be.ExecuteBlock(w.ExecutionBlock, "nse-develop22", "WidgetDev");
db1.Dispose();
db2.Dispose();
Database ddb1 = new Database();
Database ddb2 = new Database();
ddb1.RegisterForDataCompare(new ConnectionProperties("nse-develop22", "WidgetDev"), Options.Default);
ddb2.RegisterForDataCompare(new ConnectionProperties("nse-develop22", "WidgetLive"), Options.Default);
ComparisonSession session = new ComparisonSession();
TableMappings mappings = new TableMappings();
mappings.CreateMappings(ddb1.Tables, ddb2.Tables);
session.CompareDatabases(ddb1, ddb2, mappings);
SqlProvider provider = new SqlProvider();
ExecutionBlock ebData = provider.GetMigrationSQL(session, true);
//we want to run the SQL on WM so pass in true as the second parameter
ExecutionBlock block = provider.GetMigrationSQL(session, true);
Console.WriteLine("Migration SQL:");
Console.WriteLine(block.GetString());
BlockExecutor executor = new BlockExecutor();
executor.ExecuteBlock(block, "nse-develop22", "WidgetLive");
session.Dispose();
block.Dispose();
db1.Dispose();
db2.Dispose();
}
}
}
I want to also be able to pass a webthod of parameter, be selecting a group that contains a set number of tables from my db.
This way we can set migration to run only on that group og tables. See my Web Service below:
using System;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Xsl;
using System.Text;
using System.Reflection;
using System.Diagnostics; // for ProcessStartInfo
using RedGate.SQL.Shared;
using RedGate.SQLCompare.Engine;
using RedGate.SQLDataCompare.Engine;
namespace SQLDataCompareWebService
{
public struct ClientData
{
public String Name;
public int ID;
}
/// <summary>
/// Summary description for WebService1.
/// </summary>
[WebService(Namespace = "http://localhost/SQLCompareWebService/",
Description="This is a schema/data WebService.")]
public class SQLCompareWebService1 : System.Web.Services.WebService
{
private const int CacheTime = 1000000; // seconds
public SQLCompareWebService1()
{
//CODEGEN: This call is required by the ASP+ Web Services Designer
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
//To build, uncomment the following lines then save and build the project
//
[WebMethod]
public void DataMigration()
{
Database db1 = new Database();
Database db2 = new Database();
try
{
db1.Register(new ConnectionProperties("nse-develop22", "WidgetDev"), Options.Default);
db2.Register(new ConnectionProperties("nse-develop22", "WidgetLive"), Options.Default);
}
catch (System.Data.SqlClient.SqlException sqe)
{
Console.WriteLine("SQL Exception: " + sqe.Message);
return;
}
Differences diffs = db1.CompareWith(db2, Options.Default);
Work w = new Work();
w.BuildFromDifferences(diffs, Options.Default, true);
//Uncomment next line to get schema migration script
string schemaSQL=w.ExecutionBlock.GetString();
//Uncomment the next lines to run migration script
BlockExecutor be=new BlockExecutor();
be.ExecuteBlock(w.ExecutionBlock, "nse-develop22", "WidgetDev");
db1.Dispose();
db2.Dispose();
Database ddb1 = new Database();
Database ddb2 = new Database();
ddb1.RegisterForDataCompare(new ConnectionProperties("nse-develop22", "WidgetDev"), Options.Default);
ddb2.RegisterForDataCompare(new ConnectionProperties("nse-develop22", "WidgetLive"), Options.Default);
ComparisonSession session = new ComparisonSession();
TableMappings mappings = new TableMappings();
mappings.CreateMappings(ddb1.Tables, ddb2.Tables);
session.CompareDatabases(ddb1, ddb2, mappings);
SqlProvider provider = new SqlProvider();
ExecutionBlock ebData = provider.GetMigrationSQL(session, true);
//we want to run the SQL on WM so pass in true as the second parameter
ExecutionBlock block = provider.GetMigrationSQL(session, true);
Console.WriteLine("Migration SQL:");
Console.WriteLine(block.GetString());
BlockExecutor executor = new BlockExecutor();
executor.ExecuteBlock(block, "nse-develop22", "WidgetLive");
session.Dispose();
block.Dispose();
db1.Dispose();
db2.Dispose();
}
}
}
Comments
I have written it as
But I need it to look like
Where I can select it as an option in my webService.
Is this correct or wrong
I thought you wanted to specify the tables in web.config? This would be done at the server end...
Here is my problem, I want to use the setting configurationManager to handle the setting in my config file.
then I want to parameterize my Tables by there group name into a webmethod.
How would I accomplish this.
PLEASE HELP.
the database, server, tha tables, etc. then pass them through as parameters so they can be selected.
they will be entered into the config file manually but will need to be read using configurationManager.
Is my purpose clear. the code you setup works, but it uses XMLreader, I want to use configurationManager and pass thouse setting off as parameters to allow web service to take those parameters and set them.
So they can select a set Group, from a selected Database, to migrate to second DB.
Is this clear.
http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation(VS.80).aspx
how would I pass it as parameters so it can know which group and which tables are selected form that group.
Thanks