locked
SqlSyncDescriptionBuilder.ScopeExists Always Returns False RRS feed

  • Question

  • While provisioning a source database, I want to determine if the scope name already exists in the scope_info table.  This condition can happen when the app is aborted during the provisioning process.  I have tried the ScopeExists method of SqlSyncScopeProvisioning, but it always returns true regardless of whether or not the scope name already exists in the scope_info table.

    public bool ProvisionSource(string scopeName)
    {
        try
        {
            using (var sourceConn = new SqlConnection(ConnectionManager.CurrentConnectionString))
            {
                sourceConn.Open();
                // define a new scope named SalesScope
                var scopeDesc = new DbSyncScopeDescription(scopeName);
    
                var schemaTable = sourceConn.GetSchema("Tables");
    
                foreach (DataRow row in schemaTable.Rows)
                {
                    var tableName = row["table_schema"] + "." + row["table_name"];
                    if ((tableName == "dbo.schema_info") || (tableName == "dbo.scope_config") || (tableName == "dbo.scope_info")) continue;
    
                    var syncTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, sourceConn);
                    scopeDesc.Tables.Add(syncTableDescription);
                }
    
                // create a server scope provisioning object based on the scopeDesc
                var serverProvision = new SqlSyncScopeProvisioning(sourceConn, scopeDesc);
    
                if (!serverProvision.ScopeExists(scopeDesc.ScopeName))   //<<<---- always returns true
                {
                    // create table if it doesn't exist or use table if it already exists
                    serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
    
                    // start the provisioning process
                    serverProvision.Apply();
                }
                else
                {
                    if (Deprovision(scopeName, ConnectionManager.CurrentConnectionString))
                    {
                        ProvisionSource(scopeName);   
                    }
                }
                return true;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error when provisioning server side\r\n" + ex.Message);
            return false;
        }
    }
    How can I query the scope_info table to determine if the scope already exists?


    Rob E.




    • Edited by REvans611 Wednesday, September 9, 2015 5:35 PM
    Wednesday, September 9, 2015 3:11 PM