Exemplo n.º 1
0
        public static void ProvisionTableOnClient(string pScopeName, string pProviderConnectionString, string pClientConnectionString)
        {
            try
            {
                // create a connection to the SyncExpressDB database
                SqlConnection clientConn = new SqlConnection(pClientConnectionString);

                // create a connection to the SyncDB server database
                SqlConnection serverConn = new SqlConnection(pProviderConnectionString);
                // connection string for Eskimos test
                //SqlConnection serverConn = new SqlConnection("Data Source=q6.2eskimos.com; Initial Catalog=EskLeeTest; uid=test ; pwd=test1test");

                // get the description of ProductsScope from the SyncDB server database
                DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(pScopeName, serverConn);

                // create server provisioning object based on the ProductsScope
                SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);

                // starts the provisioning process
                clientProvision.Apply();
            }
            catch (Exception e)
            {
                string tempErrorMessage = "There was an exception whilst creating a client provision: " + e;
                Debug.WriteLine(tempErrorMessage);
                Logs.ProvisioningLog.WriteLine(tempErrorMessage);
                throw e;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string strscopename  = Properties.Settings.Default["ScopeName"].ToString();
            string strclientConn = Properties.Settings.Default["clientConn"].ToString();
            string strserverConn = Properties.Settings.Default["serverConn"].ToString();

            try
            {
                SqlConnection clientConn = new SqlConnection(@strclientConn);
                SqlConnection serverConn = new SqlConnection(@strserverConn);

                // Obtain the description of VLSummaryReport table from the server using the scope name
                DbSyncScopeDescription   scopeDesc       = SqlSyncDescriptionBuilder.GetDescriptionForScope(strscopename, serverConn);
                SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);

                clientProvision.CommandTimeout = 180000;
                clientProvision.Apply();
                Console.WriteLine("Client Successfully Provisioned.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.Data.ToString());
                Console.ReadLine();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // 客户端的连接.
            // create a connection to the SyncExpressDB database
            SqlConnection clientConn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial Catalog=SyncExpressDB; Trusted_Connection=Yes");

            // 服务端的连接.
            // create a connection to the SyncDB server database
            SqlConnection serverConn = new SqlConnection("Data Source=localhost; Initial Catalog=SyncDB; Integrated Security=True");

            // 从 服务器上, 获取 同步范围的数据.
            // get the description of ProductsScope from the SyncDB server database
            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("ProductsScope", serverConn);


            // 将同步范围的数据, 写入到客户端.
            // create server provisioning object based on the ProductsScope
            SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);

            // starts the provisioning process
            clientProvision.Apply();


            // 该应用程序,运行完毕后, 会在 SQL Server Express 服务器上面, 创建这些表:
            // Products, Products_Tracking, schema_info, scope_config, scope_info
        }
        public DbSyncScopeDescription GetScopeDescription(string scopeName, string serverConnectionString)
        {
            this.peerProvider.Connection.ConnectionString = serverConnectionString;
            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, (SqlConnection)this.dbProvider.Connection);

            return(scopeDesc);
        }
Exemplo n.º 5
0
        public DbSyncScopeDescription GetScopeDescription()
        {
            Log("GetSchema: {0}", this.peerProvider.Connection.ConnectionString);

            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(SyncUtils.ScopeName, (SqlConnection)this.dbProvider.Connection);

            return(scopeDesc);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            SqlCeConnection            clientConn      = new SqlCeConnection(@"Data Source='C:\dev\SyncTest\SyncSQLServerAndSQLCompact\data\SyncCompactDB.sdf'");
            SqlConnection              serverConn      = new SqlConnection(@"Data Source=.\SQL2008; Initial Catalog=SyncDB; Integrated Security=True");
            DbSyncScopeDescription     scopeDesc       = SqlSyncDescriptionBuilder.GetDescriptionForScope("ProductsScope", serverConn);
            SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);

            clientProvision.Apply();
        }
Exemplo n.º 7
0
        public DbSyncScopeDescription GetScopeDescription()
        {
            Log("GetSchema: {0}", sqlProvider.Connection.ConnectionString);

            var scopeDesc =
                SqlSyncDescriptionBuilder.GetDescriptionForScope(
                    sqlProvider.ScopeName, (SqlConnection)sqlProvider.Connection);

            return(scopeDesc);
        }
        public override void ProvisionTriggerAndProcedureUpdates()
        {
            Log.Info("[DistributedDb] ProvisionTriggerAndProcedureUpdates Client Start", this);

            foreach (var db in base.Databases)
            {
                var clientConn = new SqlConnection(db.ClientConnectionString);
                var serverConn = new SqlConnection(db.ServerConnectionString);
                var scopeDesc  = SqlSyncDescriptionBuilder.GetDescriptionForScope(db.Scope, serverConn);
                base.ProvisionTriggerAndProcedureUpdates(db, clientConn, scopeDesc);
            }

            Log.Info("[DistributedDb] ProvisionTriggerAndProcedureUpdates Client End", this);
        }
        public void TruncateClientTables()
        {
            Log.Info("[DistributedDb] TruncateClientTables Client Start", this);

            foreach (var db in base.Databases)
            {
                var clientConn = new SqlConnection(db.ClientConnectionString);
                var serverConn = new SqlConnection(db.ServerConnectionString);
                var scopeDesc  = SqlSyncDescriptionBuilder.GetDescriptionForScope(db.Scope, serverConn);
                base.TruncateTables(db.Tables, clientConn, scopeDesc);
            }

            Log.Info("[DistributedDb] TruncateClientTables Client End", this);
        }
Exemplo n.º 10
0
        private static DbSyncScopeDescription GetScopeDescription(Scope scope, DbConnection conn)
        {
            DbSyncScopeDescription scopeDesc = null;

            if (conn is SqlCeConnection)
            {
                scopeDesc = SqlCeSyncDescriptionBuilder.GetDescriptionForScope(scope.ToScopeString(), prefix, (SqlCeConnection)conn);
            }
            else if (conn is SqlConnection)
            {
                scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scope.ToScopeString(), prefix, (SqlConnection)conn);
            }

            return(scopeDesc);
        }
        public override void Deprovision()
        {
            Log.Info("[DistributedDb] Deprovision Client Start", this);

            foreach (var db in base.Databases)
            {
                var clientConn = new SqlConnection(db.ClientConnectionString);
                var serverConn = new SqlConnection(db.ServerConnectionString);
                var scopeDesc  = SqlSyncDescriptionBuilder.GetDescriptionForScope(db.Scope, serverConn);
                base.Deprovision(db, clientConn, scopeDesc);
            }

            base.DeprovisionStore(new SqlConnection(base.Configuration.ClientConnectionString));

            Log.Info("[DistributedDb] Deprovision Client End", this);
        }
Exemplo n.º 12
0
        public void ProvisionClient(string TableName)
        {
            DbSyncScopeDescription scopeDescription = SqlSyncDescriptionBuilder.GetDescriptionForScope(TableName + _filter, _serverConnection);

            SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(_localConnection, scopeDescription);

            if (!clientProvision.ScopeExists(scopeDescription.ScopeName))
            {
                clientProvision.Apply();
                Log.WriteLogs("Client " + TableName + " was provisioned.");
            }
            else
            {
                Log.WriteLogs("Client " + TableName + " was already provisioned.");
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Check to see if the passed in  SqlSyncProvider needs Schema from server
        /// </summary>
        /// <param name="localProvider"></param>
        private void CheckIfProviderNeedsSchema(SqlSyncProvider localProvider)
        {
            if (localProvider != null)
            {
                SqlConnection            sqlConn   = (SqlConnection)localProvider.Connection;
                SqlSyncScopeProvisioning sqlConfig = new SqlSyncScopeProvisioning(sqlConn);

                string scopeName = localProvider.ScopeName;
                if (!sqlConfig.ScopeExists(scopeName))
                {
                    DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(SyncUtils.ScopeName, (System.Data.SqlClient.SqlConnection)(sqlSharingForm.providersCollection["Peer1"]).Connection);
                    sqlConfig.PopulateFromScopeDescription(scopeDesc);
                    sqlConfig.Apply();
                }
            }
        }
Exemplo n.º 14
0
 private static bool checkScope(SqlConnection connection)
 {
     try
     {
         SqlSyncDescriptionBuilder.GetDescriptionForScope("SyncScope", connection);
     }
     catch (Exception)
     {
         return(false);
     }
     finally
     {
         connection.Close();
     }
     return(true);
 }
Exemplo n.º 15
0
        private static void ProvisioningLocal()
        {
            var connectionLocal  = new SqlConnection(ConfigurationManager.AppSettings["connectionLocal"]);
            var connectionRemote = new SqlConnection(ConfigurationManager.AppSettings["connectionRemote"]);

            var descriptionScope = SqlSyncDescriptionBuilder.GetDescriptionForScope("ProductScope", connectionRemote);
            var provisionLocal   = new SqlSyncScopeProvisioning(connectionLocal, descriptionScope);

            try
            {
                provisionLocal.Apply();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[ERROR] {ex.Message}");
            }
        }
Exemplo n.º 16
0
        private void setupScopeToolStripMenuItem_Click(object sender, EventArgs e)
        {
#if (DEBUG)
            SqlConnection clientConn = new SqlConnection(Program.str_debug_clientConn);
#else
            SqlConnection clientConn = new SqlConnection(Program.str_release_clientConn);
#endif
            SqlConnection serverConn = new SqlConnection(Program.str_serverConn);
            // define a new scope named PayPalSyncScope
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("PayPalSyncScope");

            // get the description of the tblpaypal table from SERVER database
            DbSyncTableDescription tblpaypalDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("tblpaypal", serverConn);

            // add the table description to the sync scope definition
            scopeDesc.Tables.Add(tblpaypalDesc);

            // create a server scope provisioning object based on the PayPalSyncScope
            SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

            // skipping the creation of table since table already exists on server
            serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

            // start the provisioning process
            serverProvision.Apply();

            Console.WriteLine("Server Successfully Provisioned.");

            // get the description of SyncScope from the server database
            DbSyncScopeDescription scopeDesc2 = SqlSyncDescriptionBuilder.GetDescriptionForScope("PayPalSyncScope", serverConn);

            // create server provisioning object based on the SyncScope
            SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc2);

            // starts the provisioning process
            clientProvision.Apply();

            DialogResult result = DotNetPerls.BetterDialog.ShowDialog(
                "Trans2Summa3060",                                          //titleString
                "Client and Server Successfully Provisioned.",              //bigString
                null,                                                       //smallString
                null,                                                       //leftButton
                "OK",                                                       //rightButton
                global::Trans2Summa3060.Properties.Resources.Message_info); //iconSet
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            //UpgradeDatabasewithCaseSensitive();

            // create a connection to the SyncCompactDB database
            SqlCeConnection clientConn = new SqlCeConnection(@"Data Source='C:\VisualStudioProjects\SyncSQLServerAndSQLCompact\ClientSQLCompactDB\SyncCompactDB.sdf'");

            // create a connection to the SyncDB server database
            SqlConnection serverConn = new SqlConnection("Data Source=localhost; Initial Catalog=SyncDB; Integrated Security=True");

            // get the description of ProductsScope from the SyncDB server database
            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("ProductsScope", serverConn);

            // create CE provisioning object based on the ProductsScope
            SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);

            // starts the provisioning process
            clientProvision.Apply();
        }
Exemplo n.º 18
0
        public void ProvisionClient()

        {
            SqlConnection serverConn = new SqlConnection(sServerConnection);

            SqlConnection clientConn = new SqlConnection(sClientConnection);



            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(sScope, serverConn);

            SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);


            if (!clientProvision.ScopeExists(sScope))
            {
                clientProvision.Apply();
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {

            // 客户端的连接.
            SqlConnection clientConn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial Catalog=SyncExpressDB; Trusted_Connection=Yes");

            // 服务端的连接.
            SqlConnection serverConn = new SqlConnection("Data Source=localhost; Initial Catalog=SyncDB; Integrated Security=True");


            // 从 服务器上, 获取 同步范围的数据.
            // get description for the OrdersScope-NC scope from the SyncDB server database
            DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("OrdersScope-NC", serverConn);


            // 将同步范围的数据, 写入到客户端.
            // create a provisioning object 
            SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);

            // start the provisioning process
            clientProvision.Apply();


        }
Exemplo n.º 20
0
        /// <summary>
        /// Cài đặt SCOPE cho client từ Server SCOPE,
        /// Nếu CLIENT có SCOPE rồi sẽ bỏ qua
        /// </summary>
        /// <param name="client_connectionString"></param>
        /// <param name="server_connectionString"></param>
        public static int fetch_sync_scope(String client_connectionString, String server_connectionString, String server_scope_name)
        {
            try{
                // create a connection to the SyncCompactDB database
                SqlConnection clientConn = new SqlConnection(client_connectionString);

                // create a connection to the SyncDB server database
                SqlConnection serverConn = new SqlConnection(server_connectionString);

                // get the description of ProductsScope from the SyncDB server database
                DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(server_scope_name, serverConn);

                // create provisioning object based on the Scope
                SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);

                //starts the provisioning process
                clientProvision.Apply();
                return(1);
            }catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(-1);
            }
        }
Exemplo n.º 21
0
        public DbSyncScopeDescription GetScopeDescription(string syncScopeName)
        {
            SqlSyncScopeProvisioning serverProvision = CreateScopeProvision();

            return(serverProvision.ScopeExists(syncScopeName) ? SqlSyncDescriptionBuilder.GetDescriptionForScope(syncScopeName, (SqlConnection)DbConnection) : null);
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            // Create the connections over which provisioning and sycnhronization
            // are performed. The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information and making changes to the server database.
            SqlConnection   serverConn      = new SqlConnection(Utility.ServerConnString);
            SqlConnection   clientSqlConn   = new SqlConnection(Utility.ClientSqlConnString);
            SqlCeConnection clientSqlCeConn = new SqlCeConnection(Utility.ClientSqlCeConnString);

            // Create a scope named "filtered_customer", and add two tables to the scope.
            // GetDescriptionForTable gets the schema of each table, so that tracking
            // tables and triggers can be created for that table.
            //<snippetOCSv3_CS_Basic_SqlPeer_ScopeDesc>
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("filtered_customer");

            scopeDesc.Tables.Add(
                SqlSyncDescriptionBuilder.GetDescriptionForTable("Customer", serverConn));
            scopeDesc.Tables.Add(
                SqlSyncDescriptionBuilder.GetDescriptionForTable("CustomerContact", serverConn));
            //</snippetOCSv3_CS_Basic_SqlPeer_ScopeDesc>

            // Create a provisioning object for "filtered_customer" and specify that
            // base tables should not be created (They already exist in SyncSamplesDb_SqlPeer1).
            //<snippetOCSv3_CS_Basic_SqlPeer_ServerConfig>
            SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning(scopeDesc);

            serverConfig.CreateTableDefault = DbSyncCreationOption.Skip;

            // Specify which column(s) in the Customer table to use for filtering data,
            // and the filtering clause to use against the tracking table.
            // "[side]" is an alias for the tracking table.
            serverConfig["Customer"].AddFilterColumn("CustomerType");
            serverConfig["Customer"].FilterClause = "[side].[CustomerType] = 'Retail'";

            // Configure the scope and change tracking infrastructure.
            serverConfig.Apply(serverConn);

            // Write the configuration script to a file. You can modify
            // this script if necessary and run it against the server
            // to customize behavior.
            File.WriteAllText("SampleConfigScript.txt",
                              serverConfig.Script("SyncSamplesDb_SqlPeer1"));
            //</snippetOCSv3_CS_Basic_SqlPeer_ServerConfig>


            // Retrieve scope information from the server and use the schema that is retrieved
            // to provision the SQL Server and SQL Server Compact client databases.

            //<snippetOCSv3_CS_Basic_SqlPeer_ClientConfig>
            // This database already exists on the server.
            DbSyncScopeDescription   clientSqlDesc   = SqlSyncDescriptionBuilder.GetDescriptionForScope("filtered_customer", serverConn);
            SqlSyncScopeProvisioning clientSqlConfig = new SqlSyncScopeProvisioning(clientSqlDesc);

            clientSqlConfig.Apply(clientSqlConn);

            // This database does not yet exist.
            Utility.CreateSqlCeDatabase();
            DbSyncScopeDescription     clientSqlCeDesc   = SqlSyncDescriptionBuilder.GetDescriptionForScope("filtered_customer", serverConn);
            SqlCeSyncScopeProvisioning clientSqlCeConfig = new SqlCeSyncScopeProvisioning(clientSqlCeDesc);

            clientSqlCeConfig.Apply(clientSqlCeConn);
            //</snippetOCSv3_CS_Basic_SqlPeer_ClientConfig>


            // Initial synchronization sessions. 7 rows are synchronized:
            // all rows (4) from CustomerContact, and the 3 rows from Customer
            // that satisfy the filtering criteria.
            //<snippetOCSv3_CS_Basic_SqlPeer_InitialSync>
            SampleSyncOrchestrator  syncOrchestrator;
            SyncOperationStatistics syncStats;

            // Data is downloaded from the server to the SQL Server client.
            syncOrchestrator = new SampleSyncOrchestrator(
                new SqlSyncProvider("filtered_customer", clientSqlConn),
                new SqlSyncProvider("filtered_customer", serverConn)
                );
            syncStats = syncOrchestrator.Synchronize();
            syncOrchestrator.DisplayStats(syncStats, "initial");

            // Data is downloaded from the SQL Server client to the
            // SQL Server Compact client.
            syncOrchestrator = new SampleSyncOrchestrator(
                new SqlCeSyncProvider("filtered_customer", clientSqlCeConn),
                new SqlSyncProvider("filtered_customer", clientSqlConn)
                );
            syncStats = syncOrchestrator.Synchronize();
            syncOrchestrator.DisplayStats(syncStats, "initial");
            //</snippetOCSv3_CS_Basic_SqlPeer_InitialSync>


            // Make changes on the server: 1 insert, 1 update, and 1 delete.
            Utility.MakeDataChangesOnServer();


            // Synchronize again. Three changes were made on the server, but
            // only two of them applied to rows that are in the "filtered_customer"
            // scope. The other row is not synchronized.
            // Notice that the order of synchronization is different from the initial
            // sessions, but the two changes are propagated to all nodes.
            syncOrchestrator = new SampleSyncOrchestrator(
                new SqlCeSyncProvider("filtered_customer", clientSqlCeConn),
                new SqlSyncProvider("filtered_customer", serverConn)
                );
            syncStats = syncOrchestrator.Synchronize();
            syncOrchestrator.DisplayStats(syncStats, "subsequent");

            syncOrchestrator = new SampleSyncOrchestrator(
                new SqlSyncProvider("filtered_customer", clientSqlConn),
                new SqlCeSyncProvider("filtered_customer", clientSqlCeConn)
                );
            syncStats = syncOrchestrator.Synchronize();
            syncOrchestrator.DisplayStats(syncStats, "subsequent");

            serverConn.Close();
            serverConn.Dispose();
            clientSqlConn.Close();
            clientSqlConn.Dispose();
            clientSqlCeConn.Close();
            clientSqlCeConn.Dispose();

            Console.Write("\nPress any key to exit.");
            Console.Read();
        }