안녕하세요, 나는 2 개의 다른 데이터베이스와 테이블 및 columns.i 동기화 동기화 응용 프로그램을 만들었습니다. 동기화 프레임 워크를 사용하여 azure는 azure에서 호스팅합니다. 또한 내가 기사 아래에 읽었습니다 :어떻게 2 개의 다른 데이터베이스 테이블에서 다른 열의 이름을 동기화 할 수 있습니까?
http://jtabadero.wordpress.com/2011/08/19/part-4-synchronizing-tables-with-different-table-names-and-column-names/ http://www.devart.com/dotconnect/oracle/docs/SyncFramework.html
하지만 난 Nullreference 예외가 있습니다. OrderTable에 올바른 열이 없습니다. 사진을보세요. 이 문제를 해결하는 방법.
namespace WorkerRole1
{
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
// This is a sample worker implementation. Replace with your logic.
Trace.TraceInformation("WorkerRole1 entry point called", "Information");
Setup();
while (true)
{
Sync();
Thread.Sleep(10000);
Trace.TraceInformation("Working", "Information");
}
}
private void Setup()
{
string scopeName = "DifferentSchemaScope";
string MemberSQLAzureConnectionString = ConfigurationManager.ConnectionStrings["MemberSQLAzureConnectionString"].ConnectionString;
string HubSQLAzureConnectionString = ConfigurationManager.ConnectionStrings["HubSQLAzureConnectionString"].ConnectionString;
using (SqlConnection sqlMemberAzureConn = new SqlConnection(MemberSQLAzureConnectionString))
{
using (SqlConnection sqlHubAzureConn = new SqlConnection(HubSQLAzureConnectionString))
{
if (sqlHubAzureConn.State == System.Data.ConnectionState.Open && sqlMemberAzureConn.State == ConnectionState.Open)
{
DbSyncScopeDescription myScope = new DbSyncScopeDescription(scopeName);
DbSyncTableDescription serverTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("myTest.SourceOrderTable", sqlHubAzureConn);
serverTableDesc.GlobalName = "OrderTable";
DbSyncTableDescription clientTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("myTest.DestinationOrderTable", sqlMemberAzureConn);
clientTableDesc.GlobalName = "OrderTable";
myScope.Tables.Add(serverTableDesc);
myScope.Tables.Add(clientTableDesc);
SqlSyncScopeProvisioning sqlServerProv = new SqlSyncScopeProvisioning(myScope);
SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(myScope);
sqlServerProv.PopulateFromScopeDescription(myScope);
myScope.Tables["OrderTable"].Columns.Remove(myScope.Tables["OrderTable"].Columns["OrderQty"]);
myScope.Tables["OrderTable"].Columns["OrderId"].IsPrimaryKey = true;
sqlAzureProv.PopulateFromScopeDescription(myScope);
if (!sqlServerProv.ScopeExists(scopeName, sqlHubAzureConn))
{
sqlServerProv.Apply(sqlHubAzureConn);
}
// sqlAzureProv.SetCreateTableDefault(DbSyncCreationOption.Skip);
if (!sqlAzureProv.ScopeExists(scopeName, sqlMemberAzureConn))
{
sqlAzureProv.Apply(sqlMemberAzureConn);
}
}
}
}
}
private void Sync()
{
string scopeName = "DifferentSchemaScope";
string MemberSQLAzureConnectionString = ConfigurationManager.ConnectionStrings["MemberSQLAzureConnectionString"].ConnectionString; //CloudConfigurationManager.GetSetting("MemberSQLAzureConnectionString");
string HubSQLAzureConnectionString = ConfigurationManager.ConnectionStrings["HubSQLAzureConnectionString"].ConnectionString; //CloudConfigurationManager.GetSetting("HubSQLAzureConnectionString");
using (SqlConnection sqlMemberAzureConn = new SqlConnection(MemberSQLAzureConnectionString))
{
using (SqlConnection sqlHubAzureConn = new SqlConnection(HubSQLAzureConnectionString))
{
var localProvider = new SqlSyncProvider(scopeName, sqlHubAzureConn);
var remoteProvider = new SqlSyncProvider(scopeName, sqlMemberAzureConn);
remoteProvider.ChangesSelected += remoteProvider_ChangesSelected;
SyncOrchestrator syncOrchestrator = new SyncOrchestrator
{
LocalProvider = localProvider,
RemoteProvider = remoteProvider,
Direction = SyncDirectionOrder.UploadAndDownload
};
syncOrchestrator.Synchronize();
}
}
}
void remoteProvider_ChangesSelected(object sender, DbChangesSelectedEventArgs e)
{
if (e.Context.DataSet.Tables.Contains("OrderTable"))
{
DataTable dataTable = new DataTable();
dataTable = e.Context.DataSet.Tables["OrderTable"];
//rename the columns to match the destination table’s column names
dataTable.Columns["OrderId"].ColumnName = "OrderNo";
dataTable.Columns["OrderDesc"].ColumnName = "OrderDetail";
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
}
}
SQL :.
이드
스키마 MYTEST가TABLE [MYTEST]을 만들기 .... 기본 키이어야한다 [SourceOrderTable ( [ OrderID] [int] IDENTITY (1,1) NULL이 아닌 [OrderDesc] nvarchar NULL)
CREATE TABLE [myTest].[DestinationOrderTable](
[OrderNo] [int] IDENTITY(1,1) NOT NULL,
[OrderDetail] [nvarchar](50) NULL,
[OrderQty] int NULL)
하지만 작동하지 않습니다. 그것은 "무효 remoteProvider_ChangesSelected (개체를 보낸 사람, DbChangesSelectedEventArgs 전자)"remoteprovider 열 이름이 아닌 changed.remoteProvider 열 이름이 "OrderNo, OrderDetail"입니다 왜 그건에 오류가 발생하지만 "ORDERID, OrderDesc"모양 사진이어야합니다
ERROR 사진 :
가능한 중복 이제까지*. –
내 질문에 대한 오해. 이 문제를 해결하기에 충분한 정보가 있습니다. RemoteProvider 테이블에 orderid, orderdesc.WHY가 포함되어 있지 않습니다? 내 코드와 기사를 보았 니? – Penguen
코드를 읽었습니다. 특별히 다음 행의 다른 것에 할당하기 때문에 특별한 이유없이'dataTable'을 생성합니다. –