Answered by:
ScopeExists Method not working

Question
-
I have written the following code
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverCon); List<string> tableList = configHelper.GetTables(dbName); foreach (string table in tableList) { string scopeName = dbName + "-" + table + "-" + "Scope"; if (!serverProvision.ScopeExists(scopeName)) { DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(scopeName); DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(table, serverCon); scopeDesc.Tables.Add(tableDesc); serverProvision = new SqlSyncScopeProvisioning(serverCon, scopeDesc); serverProvision.ObjectSchema = schema; serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip); serverProvision.Apply(); } }
But I still get the exception
Could not create a scope with name 'TestDB2-TestTable1-Scope' as a scope with that name already exists.
at Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning.ApplyScope(SqlConnection connection)
at Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning.ApplyInternal(SqlConnection connection)
at Microsoft.Synchronization.Data.SqlServer.SqlSyncScopeProvisioning.Apply()
at SyncFrameworkTest.DataSynchronizer.ProvisionDatabases() in C:\myapps\SyncFramework\SyncFrameworkTest\DataSynchroni
zer.cs:line 75
at SyncFrameworkTest.Program.Main(String[] args) in C:\myapps\SyncFramework\SyncFrameworkTest\Program.cs:line 11Why am I getting this exception because I am already checking for ScopeExists?
Friday, February 25, 2011 1:43 PM
Answers
-
have you tried setting the ObjectSchema on serverProvision outside the foreach loop before calling ScopeExists?
- Marked as answer by MSDN Student Monday, February 28, 2011 2:02 PM
Monday, February 28, 2011 1:27 PM
All replies
-
If the scope exists already on the server, can you verify what the check is returning in your debugger?
Also why are you instantiating the serverProvision outside the check and then creating another one?
This posting is provided AS IS with no warranties, and confers no rightsSaturday, February 26, 2011 1:43 AM -
The scope already exists on the server because the first run of this code was successfuly. I started getting the exception only on the second run.
Now the ScopeExists method is not static. so I need an instance of the SqlSyncScopeProvisioning class in order to be able to call ScopeExists method.
Saturday, February 26, 2011 6:43 PM -
have you tried setting the ObjectSchema on serverProvision outside the foreach loop before calling ScopeExists?
- Marked as answer by MSDN Student Monday, February 28, 2011 2:02 PM
Monday, February 28, 2011 1:27 PM