none
NullReferenceException at CreateNewScopeForClient() - Multiple schemas

    السؤال

  • Hi, i am trying to make sync work with a Database with two non-dbo schemas, but i am receiving the following error (Fiddler output):

     

    <ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services"
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <ErrorDescription>
    System.NullReferenceException&#xD; Object reference not set to an instance of an object.&#xD; at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.CreateNewScopeForClient()&#xD; at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.GetChanges(Byte[] clientKnowledgeBlob)&#xD; at Microsoft.Synchronization.Services.DownloadChangesRequestProcessor.ProcessRequest(Request incomingRequest)&#xD; at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody)&#xD; &#xD; &#xD; </ErrorDescription>
    </ServiceError>

     

    Here is my configuration file description:

     

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="SyncConfiguration"
    type="Microsoft.Synchronization.ClientServices.Configuration.SyncConfigurationSection, SyncSvcUtil, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
    allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication"
    overrideModeDefault="Allow" restartOnExternalChanges="true" requirePermission="true" /> </configSections> <SyncConfiguration> <SyncScopes> <SyncScope Name="Scope1" SchemaName="schema1" EnableBulkApplyProcedures="true" IsTemplateScope="true"> <SyncTables> <SyncTable Name="schema1.Persons" IncludeAllColumns="true" FilterClause="[side].Id = @Id" SchemaName="schema1"> <SyncColumns> <SyncColumn Name="Id" GlobalName="Id" SqlType="uniqueidentifier" IsPrimaryKey="true" IsNullable="false" /> <SyncColumn Name="Name" GlobalName="Name" SqlType="varchar" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="Surname" GlobalName="Surname" SqlType="varchar" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="BirthDate" GlobalName="BirthDate" SqlType="date" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="Gender" GlobalName="Gender" SqlType="char" IsPrimaryKey="false" IsNullable="true" /> </SyncColumns> <FilterColumns> <FilterColumn Name="Id" /> </FilterColumns> <FilterParameters> <FilterParameter Name="@Id" SqlType="uniqueidentifier" DataSize="0" /> </FilterParameters> </SyncTable> </SyncTables> </SyncScope> <SyncScope Name="Scope2" SchemaName="schema2" EnableBulkApplyProcedures="true" IsTemplateScope="true"> <SyncTables> <SyncTable Name="schema2.Persons" IncludeAllColumns="true" FilterClause="[side].Id = @Id" SchemaName="schema2"> <SyncColumns> <SyncColumn Name="Id" GlobalName="Id" SqlType="uniqueidentifier" IsPrimaryKey="true" IsNullable="false" /> <SyncColumn Name="Name" GlobalName="Name" SqlType="varchar" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="Surname" GlobalName="Surname" SqlType="varchar" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="BirthDate" GlobalName="BirthDate" SqlType="date" IsPrimaryKey="false" IsNullable="true" /> <SyncColumn Name="Gender" GlobalName="Gender" SqlType="char" IsPrimaryKey="false" IsNullable="true" /> </SyncColumns> <FilterColumns> <FilterColumn Name="Id" /> </FilterColumns> <FilterParameters> <FilterParameter Name="@Id" SqlType="uniqueidentifier" DataSize="0" /> </FilterParameters> </SyncTable> </SyncTables> </SyncScope> </SyncScopes> <Databases> <TargetDatabase Name="XXXXX" DbServer="XXXXXXX" DbName="XXXXX" UserName="XXXXX" Password="XXXXXX" /> </Databases> </SyncConfiguration> </configuration>

     

    I am working with an azure sql database, provisioned using SyncSvcUtil.exe.

    The service diag page shows that provisioning fails, but i think it is a bug in the diagnostics page as mentioned here: http://social.msdn.microsoft.com/Forums/en-AU/synclab/thread/cf9466f7-2ea3-4418-8441-55cb71a222a1

    My InitializeService code is the following:

     

    public static void InitializeService(Microsoft.Synchronization.Services.ISyncServiceConfiguration config)
    {
        config.ServerConnectionString = "Server=XXXXX;Database=XXXXX;User ID=XXXXX;Password=XXXXX;Trusted_Connection=False;";
        config.AddFilterParameterConfiguration("id", "schema1.Persons", "@Id", typeof(System.Guid));
    
        // enable Diagnostic Dashboard feature for the service 
        config.EnableDiagnosticPage = true;
    
        // enable verbose errors 
        config.UseVerboseErrors = true;
    
        config.SetSyncObjectSchema("schema1");
    }
    

     

    I appreciate your help.

    Thanks in advance,

    Sebastián Rosales

     

     



    22/ذو الحجة/1432 05:44 م

جميع الردود

  • for the tablenames, have you tried specifying the table name without the schema?

    i.e.,  "Persons" instead of  "schema1.Persons"

    26/ذو الحجة/1432 04:07 ص
    المشرف
  • for the tablenames, have you tried specifying the table name without the schema?

    i.e.,  "Persons" instead of  "schema1.Persons"

    Hi, thanks for your help. I hadn't tried that because i was following this doc:

    http://msdn.microsoft.com/en-us/library/gg299039%28v=sql.110%29.aspx

    In SyncTable section it says:

    • Name – Table name in the database. If table is in non dbo schema, the schema name should be included. For non-dbo schemas, the schema name must be specified in quoted format. Ex: [NonDboSchema].[Customer].

     

    However, i tried specifiying the table name without schema as you suggest but i get this error in SyncSvcUtil:

     

    Reading specified config file...
    Generating DbSyncScopeDescription for scope Scope1...
    Microsoft.Synchronization.Data.DbSchemaException: Cannot obtain the schema for the following tables: Persons. Ensure that you can establish a connection to the database and that the tables exist. Check the inner exception for any store-specific errors. ---> System.Data.SqlClient.SqlException: Invalid object name 'Persons'.
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillSchemaInternal(DataSet dataset, DataTable datatable, SchemaType schemaType, IDbCommand command, String srcTable, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillSchema(DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillSchema(DataTable dataTable, SchemaType schemaType)
       at Microsoft.Synchronization.Data.DbSyncSchemaBuilder.FillSchema(IDbConnection connection, String tableName, IDbCommand schemaCmd, DataTable dataTable)
       at Microsoft.Synchronization.Data.DbSyncSchemaBuilder.GetSchemaFromDatabase(IDbConnection connection, Collection`1& missingTables, Exception& exp)
       --- End of inner exception stack trace ---
       at Microsoft.Synchronization.Data.DbSyncSchemaBuilder.GetSchema(IDbConnection connection)
       at Microsoft.Synchronization.Data.DbSyncTableDescriptionBuilder.FromCommand(String tableName, IDbCommand cmd)
       at Microsoft.Synchronization.Data.SqlServer.SqlSyncDescriptionBuilder.GetDescriptionForTable(String tableName, SqlCommand command)
       at Microsoft.Synchronization.Data.SqlServer.SqlSyncDescriptionBuilder.GetDescriptionForTable(String tableName, Collection`1 columnNames, SqlConnection connection)
       at Microsoft.Synchronization.Data.SqlServer.SqlSyncDescriptionBuilder.GetDescriptionForTable(String tableName, SqlConnection connection)
       at Microsoft.Synchronization.ClientServices.SyncSvcUtil.GetDbSyncScopeDescription(SelectedConfigSections selectedConfig)
       at Microsoft.Synchronization.ClientServices.SyncSvcUtil.ProcessConfigFile(ArgsParser parser)
       at Microsoft.Synchronization.ClientServices.SyncSvcUtil.Main(String[] args)
    SyncSvcUtil failed.
    

     


    I also tried removing schema name inside InitializeService but it does not work (same error as first post)

     

    config.AddFilterParameterConfiguration("id", "Persons", "@Id", typeof(System.Guid));
    

    I don't know what i'm doing wrong, i would appreciate any help. ¿Is it possible to sync tables with non dbo schemas or is it not supported?

     

     

    Thanks

    Sebastián Rosales


    26/ذو الحجة/1432 11:21 ص
  • Sync framework supports non-dbo schema.

    have you tried provisioning directly using SyncSvcUtilHelper?

    the xml file generated by the utility doesnt specify the schema directly on the SyncTable and looks like this:

      <SyncTable Name="[schema1].[Table_1]" GlobalName="" SchemaName=""

    so you might want to try to remove the SchemaName at the SyncTable

     

    26/ذو الحجة/1432 12:52 م
    المشرف
  • Sync framework supports non-dbo schema.

    have you tried provisioning directly using SyncSvcUtilHelper?

    the xml file generated by the utility doesnt specify the schema directly on the SyncTable and looks like this:

      <SyncTable Name="[schema1].[Table_1]" GlobalName="" SchemaName=""

    so you might want to try to remove the SchemaName at the SyncTable

     

    Thanks again for your help, i generated the config file using the UI utility and generated this:

     

    <SyncScopes>
                <SyncScope Name="Scope1" SchemaName="schema1" IsTemplateScope="true"
                    EnableBulkApplyProcedures="true">
                    <SyncTables>
                        <SyncTable Name="[schema1].[Persons]" GlobalName="Persons" SchemaName=""
                            IncludeAllColumns="true" FilterClause="[side].Id = @Id">
                            <SyncColumns>
                                <SyncColumn Name="Id" GlobalName="Id" SqlType="uniqueidentifier"
                                    IsPrimaryKey="true" IsNullable="false" />
                                <SyncColumn Name="Name" GlobalName="Name" SqlType="varchar" IsPrimaryKey="false"
                                    IsNullable="true" />
                                <SyncColumn Name="Surname" GlobalName="Surname" SqlType="varchar"
                                    IsPrimaryKey="false" IsNullable="true" />
                                <SyncColumn Name="BirthDate" GlobalName="BirthDate" SqlType="date"
                                    IsPrimaryKey="false" IsNullable="true" />
                                <SyncColumn Name="Gender" GlobalName="Gender" SqlType="char"
                                    IsPrimaryKey="false" IsNullable="true" />
                            </SyncColumns>
                            <FilterColumns>
                                <FilterColumn Name="Id" />
                            </FilterColumns>
                            <FilterParameters>
                                <FilterParameter Name="@Id" SqlType="uniqueidentifier" DataSize="0" />
                            </FilterParameters>
                        </SyncTable>
                    </SyncTables>
                </SyncScope>
                <SyncScope Name="Scope2" SchemaName="schema2" IsTemplateScope="true"
                    EnableBulkApplyProcedures="true">
                    <SyncTables>
                        <SyncTable Name="[schema2].[Persons]" GlobalName="Persons" SchemaName=""
                            IncludeAllColumns="true" FilterClause="[side].Id = @Id">
                            <SyncColumns>
                                <SyncColumn Name="Id" GlobalName="Id" SqlType="uniqueidentifier"
                                    IsPrimaryKey="true" IsNullable="false" />
                                <SyncColumn Name="Name" GlobalName="Name" SqlType="varchar" IsPrimaryKey="false"
                                    IsNullable="true" />
                                <SyncColumn Name="Surname" GlobalName="Surname" SqlType="varchar"
                                    IsPrimaryKey="false" IsNullable="true" />
                                <SyncColumn Name="BirthDate" GlobalName="BirthDate" SqlType="date"
                                    IsPrimaryKey="false" IsNullable="true" />
                                <SyncColumn Name="Gender" GlobalName="Gender" SqlType="char"
                                    IsPrimaryKey="false" IsNullable="true" />
                            </SyncColumns>
                            <FilterColumns>
                                <FilterColumn Name="Id" />
                            </FilterColumns>
                            <FilterParameters>
                                <FilterParameter Name="@Id" SqlType="uniqueidentifier" DataSize="0" />
                            </FilterParameters>
                        </SyncTable>
                    </SyncTables>
                </SyncScope>
            </SyncScopes>
    

     


    As the global name was generated as "Persons" i changed my InitializeService code to this:

     

    config.AddFilterParameterConfiguration("id", "Persons", "@Id", typeof(System.Guid));
    

     


    Now i receive another error (Fiddler output):

     

    <ServiceError
    	xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services"
    	xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    	<ErrorDescription>System.Data.SqlClient.SqlException&#xD;
    		Invalid object name 'scope_info'.&#xD;
    		   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)&#xD;
    		   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)&#xD;
    		   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()&#xD;
    		   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)&#xD;
    		   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()&#xD;
    		   at System.Data.SqlClient.SqlDataReader.get_MetaData()&#xD;
    		   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)&#xD;
    		   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)&#xD;
    		   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)&#xD;
    		   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)&#xD;
    		   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)&#xD;
    		   at System.Data.SqlClient.SqlCommand.ExecuteReader()&#xD;
    		   at Microsoft.Synchronization.Data.SqlServer.SqlProviderFactory.ReadConfiguration(String scopeName, SyncSchemaInfo syncSchemaInfo)&#xD;
    		   at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.Configure()&#xD;
    		   at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.BeginSession(SyncProviderPosition position, SyncSessionContext syncSessionContext)&#xD;
    		   at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.GetChanges(Byte[] clientKnowledgeBlob)&#xD;
    		   at Microsoft.Synchronization.Services.DownloadChangesRequestProcessor.ProcessRequest(Request incomingRequest)&#xD;
    		   at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody)&#xD;
    		&#xD;
    		&#xD;
    	</ErrorDescription>
    </ServiceError>
    

     


    I think that the error i'm getting now is related to this issue:

    http://social.msdn.microsoft.com/Forums/en-HK/synclab/thread/5a870144-ec72-4ecd-bd6c-3c9f9302362d

    If it is the same issue, apparently it is a bug and is going to be solved in the next release, but that response was about 1 year ago. If it is the same error, do you know if it was or will be solved? Or is it another error?

     

    Thanks for your help!

    Sebastián Rosales


    26/ذو الحجة/1432 02:57 م
  • can you confirm that the sync objects were actually provisioned?

    if the objects were provisioned, under what schema was scope_info created?

    btw, i noticed you're not setting which scope to use in the InitializeService. e.g., config.SetEnableScope("Scope1");


    are you using the latest bits from the Sync Toolkit?
    27/ذو الحجة/1432 01:08 ص
    المشرف
  • can you confirm that the sync objects were actually provisioned?

    if the objects were provisioned, under what schema was scope_info created?

    Yes, the sync objects were provisioned under schema1 and schema2. These are my tables:

    schema1.Persons_tracking
    schema1.schema_info
    schema1.scope_config
    schema1.scope_info
    schema1.scope_parameters
    schema1.scope_templates

    schema2.Persons_tracking
    schema2.schema_info
    schema2.scope_config
    schema2.scope_info
    schema2.scope_parameters
    schema2.scope_templates

    and these are the store procedures:

    schema1.Persons_bulkdelete
    schema1.Persons_bulkinsert
    schema1.Persons_bulkupdate
    schema1.Persons_delete
    schema1.Persons_deletemetadata
    schema1.Persons_insert
    schema1.Persons_insertmetadata
    schema1.Persons_selectchanges
    schema1.Persons_selectrow
    schema1.Persons_update
    schema1.Persons_updatemetadata

    schema2.Persons_bulkdelete
    schema2.Persons_bulkinsert
    schema2.Persons_bulkupdate
    schema2.Persons_delete
    schema2.Persons_deletemetadata
    schema2.Persons_insert
    schema2.Persons_insertmetadata
    schema2.Persons_selectchanges
    schema2.Persons_selectrow
    schema2.Persons_update
    schema2.Persons_updatemetadata

     

    btw, i noticed you're not setting which scope to use in the InitializeService. e.g., config.SetEnableScope("Scope1");

    You are right about "config.SetEnableScope("Scope1")", i have that line in my code but i deleted by mistake on first post, i'm sorry. This is my last complete code:

    public static void InitializeService(Microsoft.Synchronization.Services.ISyncServiceConfiguration config)
    {
    	config.ServerConnectionString = "Server=XXXXXX;Database=XXXXXX;User ID=XXXXXX;Password=XXXXXX;Trusted_Connection=False;";
    	config.SetEnableScope("Scope1");
    
    	// configure filter parameters used by the service
    	config.AddFilterParameterConfiguration("id", "Persons", "@Id", typeof(System.Guid));
    
    	// enable Diagnostic Dashboard feature for the service 
    	config.EnableDiagnosticPage = true;
    
    	// enable verbose errors 
    	config.UseVerboseErrors = true;
    
    	// Note: The scope has specified a non dbo schema for creating sync tables. Removing this line will cause requests from new clients to fail.
    	config.SetSyncObjectSchema("schema1");
    }
    

    are you using the latest bits from the Sync Toolkit?

    How can i check that? The version i'm working with was downloaded as explained here:

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=12012

     

    Thanks again

    Sebastián Rosales

    27/ذو الحجة/1432 10:45 ص
  • that's the CTP copy.

    the CTP has been released as the Sync Framework Toolkit. you can find the latest bits here: http://code.msdn.microsoft.com/Sync-Framework-Toolkit-4dc10f0e

     

    27/ذو الحجة/1432 11:07 ص
    المشرف