Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to synchronize two databases in SQL Server 2008 by using C#.
I followed this article below but I got some problems.
http://msdn.microsoft.com/en-us/library/ff928758(v=SQL.110).aspx[^]

I can obtain it within two databases on a single computer.
But when I was trying to synchronize two databases which were on different computers, I got some errors at
"SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);"

Could someone help me?
Thank you very much~~


This is my complete code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;


using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServer;


namespace ProvisionClient
{
class Program
{
static void Main(string[] args)
{
SqlConnection clientConn = new SqlConnection(@"Data
Source=.\\SQLEXPRESS; Initial Catalog=SyncExpressDB;
Trusted_Connection=Yes");


SqlConnection serverConn = new SqlConnection("Data
Source=192.168.8.45\\SQLEXPRESS,1433;
Initial Catalog=SyncDB;
User ID=sa;Password=123");


DbSyncScopeDescription scopeDesc =
SqlSyncDescriptionBuilder.GetDescriptionForScope
("ProductsScope", serverConn);

error is here
====> SqlSyncScopeProvisioning clientProvision = new
SqlSyncScopeProvisioning(clientConn, scopeDesc);


clientProvision.SetCreateTableDefault
(DbSyncCreationOption.CreateOrUseExisting);

clientProvision.Apply();
}
}
}
Posted

By the way, I think the server is OK because I can connect it by ODBC and Visual Studio Server Explorer
 
Share this answer
 
This is error message. So sorry for non-english version.


未處理的例外狀況: System.InvalidOperationException: 執行個體失敗。
於 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternal
ConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Bool
ean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
owningObject)
於 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire,
SqlConnection owningObject)
於 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host
, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject
, SqlConnectionString connectionOptions, Int64 timerStart)
於 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnecti
on owningObject, SqlConnectionString connectionOptions, String newPassword, Bool
ean redirectedUserInstance)
於 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdent
ity identity, SqlConnectionString connectionOptions, Object providerInfo, String
newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
於 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOp
tions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningConnection)
於 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConn
ection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
於 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owning
Object)
於 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection o
wningObject)
於 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection ownin
gObject)
於 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)
於 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)
於 System.Data.SqlClient.SqlConnection.Open()
於 Microsoft.Synchronization.Data.SyncUtil.TryOpenConnection(IDbConnection co
nnection)
於 Microsoft.Synchronization.Data.SyncUtil.OpenConnection(IDbConnection conne
ction)
於 Microsoft.Synchronization.Data.SqlServer.SqlEditionHelper.GetEdition(SqlCo
nnection connection)
於 Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning.set_Conn
ection(SqlConnection value)
於 Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning..ctor(Sq
lConnection connection, DbSyncScopeDescription scopeDescription, SqlSyncScopePro
visioningType provisioningType, Boolean expectConnection)
於 Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning..ctor(Sq
lConnection connection, DbSyncScopeDescription scopeDescription)
於 ProvisionClient.Program.Main(String[] args) 於 C:\Users\Administrator\Desk
top\新增資料夾\SyncSQLServerAndSQLExpress\ProvisionClient\Program.cs: 行 33
請按任意鍵繼續 . . .
 
Share this answer
 
It turned out that should be

SqlConnection clientConn = new SqlConnection(@"Data
Source=.\SQLEXPRESS; Initial Catalog=SyncExpressDB;
Trusted_Connection=Yes");

there should be only one / while putting '@' before a string

>"<</xml>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900