locked
SessionVariableException: Unable to set session parameters in DbServerSyncProvider RRS feed

  • Question

  • Hi, I'm just developing v2 of my app and I'm passing a session parameter from the version into a SelectIncrementalUpdates/InsertsCommand so that I can retrieve a select list of fields based on which build of my app is being used (in the newer version of my app, there are some extra fields that i want to retrieve).

    Anyway, from v2 of my app, I'm passing a session parameter called '@BuildNumber' so that my stored procedure can do some conditional logic when it is building the select list.

    The first version of my app doesn't have this BuildNumber session parameter, so when it is synchronizing, I am getting an error (and the sync is failing):

    SessionVariableException: Unable to set session parameters in DbServerSyncProvider. Cannot obtain the value for command parameter '@BuildNumber'

    The server code is:
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand = new
     System.Data.SqlClient.SqlCommand();<br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.CommandText = "syncIncidents_SelectIncrementalInserts"
    ; <br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.CommandType = System.Data.CommandType.StoredProcedure;<br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new
     System.Data.SqlClient.SqlParameter("@UpdatedBy_SyncClientID"
    , SqlDbType.UniqueIdentifier)); <br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new
     System.Data.SqlClient.SqlParameter("@sync_last_received_anchor"
    , System.Data.SqlDbType.VarBinary));<br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new
     System.Data.SqlClient.SqlParameter("@sync_new_received_anchor"
    , System.Data.SqlDbType.VarBinary));<br/>
    IncidentsSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new
     System.Data.SqlClient.SqlParameter("@BuildNumber"
    , System.Data.SqlDbType.Int));<br/>
                
    
    How can I test that this BuildNumber value exists before I try to add the SqlParameter into the command object? I'd like to do something like:

    if (BuildNumber parameter doesn't exist) { set a default value, or alternatively, don't try to add it to the SqlParameter collection as I have a default value set in the stored proc } 

    Is this possible to do? Any help appreciated...

    Jon
    • Moved by Mahesh DudgikarMicrosoft employee Wednesday, November 25, 2009 7:32 AM (From:SyncFx - Technical Discussion)
    • Moved by Max Wang_1983 Thursday, April 21, 2011 11:02 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, October 22, 2009 12:33 PM

All replies


  • Just worked out how to do this by adding the parameter in the SelectingChanges event handler:
     
    if (e.Session.SyncParameters.Contains("@BuildNumber") == false)
    {
       e.Session.SyncParameters.Add(new SyncParameter("@BuildNumber", 0));
    }

    However, now I've got a separate issue where the select list for build 1 is Column1, Column2, Column3 but the select list for build 2 is Column1, Column2, Column3, Column4 .

    Column4 is not selected for build1 clients, but it somehow appears in the dataset on the local device(!). Is there a way of ensuring that the dataset doesn't include this column when it is returned to the client?

    I figure it is something to do with the SchemaDataSet on the server including this column, so I think I need to remove this column from the relevant table in the SchemaDataSet before returning to the client, but I'm not sure if the SchemaDataSet is supposed to be static for all clients, or if you can change it on a session basis without affecting other users?





    Thursday, October 22, 2009 1:52 PM