/// <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 conn = (SqlConnection)localProvider.Connection; SqlSyncScopeProvisioning sqlConfig = new SqlSyncScopeProvisioning(conn); string scopeName = localProvider.ScopeName; //if the scope does not exist in this store if (!sqlConfig.ScopeExists(scopeName)) { //create a reference to the server proxy SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy(SyncUtils.ScopeName, SyncUtils.GenerateSqlConnectionString(this.serverHostName, SyncUtils.FirstPeerDBName, null, null, true)); //retrieve the scope description from the server DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(); serverProxy.Dispose(); //use scope description from server to intitialize the client sqlConfig.PopulateFromScopeDescription(scopeDesc); sqlConfig.Apply(); } } }
/// <summary> /// Check to see if the passed in SQL provider needs Schema from server. /// This method assumes the provider is remote and uses a proxy instead /// of directly leveraging a provider. /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(SqlSyncProviderProxy remoteProxy) { if (remoteProxy != null && remoteProxy.NeedsScope()) { //create a reference to the server proxy SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy(SyncUtils.ScopeName, SyncUtils.GenerateSqlConnectionString(this.serverHostName, SyncUtils.FirstPeerDBName, null, null, true)); //retrieve the scope description from the server DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(); serverProxy.Dispose(); //intitialize remote store based on scope description from the server remoteProxy.CreateScopeDescription(scopeDesc); } }
/// <summary> /// Configure the SqlSyncprovider. Note that this method assumes you have a direct conection /// to the server as this is more of a design time use case vs. runtime use case. We think /// of provisioning the server as something that occurs before an application is deployed whereas /// provisioning the client is somethng that happens during runtime (on intitial sync) after the /// application is deployed. /// /// </summary> /// <param name="hostName"></param> /// <returns></returns> public SqlSyncProvider ConfigureSqlSyncProvider(string hostName) { SqlSyncProvider provider = new SqlSyncProvider(); provider.ScopeName = SyncUtils.ScopeName; provider.Connection = new SqlConnection(SyncUtils.GenerateSqlConnectionString(hostName, SyncUtils.FirstPeerDBName, null, null, true)); //create a new scope description and add the appropriate tables to this scope DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(SyncUtils.ScopeName); //class to be used to provision the scope defined above SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning((System.Data.SqlClient.SqlConnection)provider.Connection); //determine if this scope already exists on the server and if not go ahead and provision //Note that provisioning of the server is oftentimes a design time scenario and not something //that would be exposed into a client side app as it requires DDL permissions on the server. //However, it is demonstrated here for purposes of completentess. // //Note the default assumption is that SQL Server is installed as localhost. If it's not, //please replace Environment.MachineName with the correct instance name in //SqlSharingForm.SqlSharingForm_Shown(). if (!serverConfig.ScopeExists(SyncUtils.ScopeName)) { //add the approrpiate tables to this scope scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("orders", (System.Data.SqlClient.SqlConnection)provider.Connection)); scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("order_details", (System.Data.SqlClient.SqlConnection)provider.Connection)); //note that it is important to call this after the tables have been added to the scope serverConfig.PopulateFromScopeDescription(scopeDesc); //indicate that the base table already exists and does not need to be created serverConfig.SetCreateTableDefault(DbSyncCreationOption.Skip); //provision the server serverConfig.Apply(); } //Register the BatchSpooled and BatchApplied events. These are fired when a provider is either enumerating or applying changes in batches. provider.BatchApplied += new EventHandler <DbBatchAppliedEventArgs>(provider_BatchApplied); provider.BatchSpooled += new EventHandler <DbBatchSpooledEventArgs>(provider_BatchSpooled); return(provider); }
private string GenerateConnectionString(string dbName) { return(SyncUtils.GenerateSqlConnectionString( serverNameTxtBox.Text, dbName, userNameTxtBox.Text, passwordTxtBox.Text, trustedConnChkBox.Checked)); }