Answered by:
Cannot find a valid scope in table scope_info

Question
-
I am trying to configure an N-tier sync, but have encountered the following fault:
Cannot find a valid scope with the name 'MyScope' in table '[scope_info]'. Ensure that this scope exists and that it has a corresponding valid configuration in the configuration table '[scope_config]'.
Here are the methods I am using in the web service to provision my database for sync. Am I missing something?
protected override RelationalSyncProvider ConfigureProvider(string scopeName, string connectionString) { Connection = new SqlConnection(connectionString); Connection.Open(); SqlSyncProvider provider = new SqlSyncProvider(scopeName, Connection); //create anew scope description and add the appropriate tables to this scope DbSyncScopeDescription scopeDescription = new DbSyncScopeDescription(scopeName); PopulateScopeDescription(scopeDescription); //class to be used to provision the scope defined above SqlSyncScopeProvisioning scopeProvision = new SqlSyncScopeProvisioning(Connection, scopeDescription, SqlSyncScopeProvisioningType.Template); scopeProvision.ObjectSchema = "sync"; //determine if this scope already exists on the server and if not go ahead and provision if (!scopeProvision.ScopeExists(scopeName)) { //add the approrpiate tables to this scope ConfigureScopeProvision(scopeProvision); //note that it is important to call this after the tables have been added to the scope scopeProvision.PopulateFromScopeDescription(scopeDescription); //indicate that the base table already exists and does not need to be created scopeProvision.SetCreateTableDefault(DbSyncCreationOption.Skip); scopeProvision.SetCreateTrackingTableDefault(DbSyncCreationOption.CreateOrUseExisting); //provision the server scopeProvision.Apply(); } return provider; }
protected override void ConfigureScopeProvision(SqlSyncScopeProvisioning scopeProvision)
{
foreach (string table in TableNames.ProjectFiltered)
{
SqlSyncTableProvisioning tableProvision = scopeProvision.Tables[table];
tableProvision.AddFilterColumn("ProjectID");
tableProvision.FilterClause = string.Format("(@ProjectID = -1 OR ([{0}].[ProjectID] = @ProjectID OR [{0}].[ProjectID] IN (SELECT DISTINCT [ProjectID] FROM [DataSets] WHERE [IsPublished] = 1)))", table);
tableProvision.FilterParameters.Add(new SqlParameter("@ProjectID", SqlDbType.Int));
}
foreach (var entry in TableNames.DataSetFiltered)
{
string column = entry.Key;
foreach (string table in entry.Value)
{
SqlSyncTableProvisioning tableProvision = scopeProvision.Tables[table];
tableProvision.AddFilterColumn(column);
tableProvision.FilterClause = string.Format("([{0}].[{1}] IN (SELECT [DataSets].[DataSetGUID] FROM [DataSets] WHERE (IsActive = 1) AND ([DataSets].[ProjectID] = @ProjectID OR IsPublished = 1)))", table, column);
tableProvision.FilterParameters.Add(new SqlParameter("@ProjectID", SqlDbType.Int));
}
}
}
protected override void PopulateScopeDescription(DbSyncScopeDescription scopeDescription)
{
foreach (string table in TableNames.Names)
{
scopeDescription.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(table, Connection));
}
}
Tuesday, June 11, 2013 5:15 AM
Answers
-
you are provisioning a Template, not a scope:
SqlSyncScopeProvisioning scopeProvision = new SqlSyncScopeProvisioning(Connection, scopeDescription, SqlSyncScopeProvisioningType.Template);
- Marked as answer by Karl Dickman Thursday, June 13, 2013 12:43 AM
Thursday, June 13, 2013 12:38 AM
All replies
-
have you queried the scope_info table if the scopes are actually there?Tuesday, June 11, 2013 5:37 AM
-
Thank you for your response. The scope_info table does exist, but it has zero rows.Tuesday, June 11, 2013 7:11 PM
-
I have a line in this code:
scopeProvision.PopulateFromScopeDescription(scopeDescription);
This line is not present in the filtered provision how-to. Could it be causing problems?Tuesday, June 11, 2013 7:29 PM -
if there are no entries in the scope_info table, then the scope was not provisioned.Wednesday, June 12, 2013 1:01 AM
-
If the
scopeProvision.Apply();
method was invoked (which it was, as I verified with the debugger), why wasn't the scope provisioned?Wednesday, June 12, 2013 6:52 PM -
you are provisioning a Template, not a scope:
SqlSyncScopeProvisioning scopeProvision = new SqlSyncScopeProvisioning(Connection, scopeDescription, SqlSyncScopeProvisioningType.Template);
- Marked as answer by Karl Dickman Thursday, June 13, 2013 12:43 AM
Thursday, June 13, 2013 12:38 AM -
Thank you. This is what I was looking for.Thursday, June 13, 2013 12:43 AM