none
SqlCeSyncScopeProvisioning messes up SqlCeConnection when doing ScopeExists RRS feed

  • Question

  • I'm trying a basic sync operation. The server has the same tables as the client. Server is SQL 2008 R2, client is SQL Compact.

    Currently trying to sync only one table, Officer.

    I set the server (SQL 08R2) scope, then read that to set the Client scope.

    I have this code:

    If Not clientSqlCe1Config.ScopeExists(clientSqlCe1Config.ScopeName) Then

    clientSqlCe1Config.Apply()

    End If

    I noticed that when it checks ScopeExists, the 'clientSqlCe1Conn' connection loses the password part.

    When I get to the Synchronize, it fails saying the password isn't valid.

    So, I added this line after ScopeExists:

    clientSqlCe1Conn = New SqlCeConnection("Data Source=" & newDBPath & ";password=xxxyyy1234")

    clientSqlCe1Config.Apply()

    Not sure this is the best fix... any thoughts?                  


    • Edited by M Kenyon II Wednesday, April 11, 2012 7:44 PM Fixed formatting. lines got moved on me.
    Tuesday, April 10, 2012 9:42 PM

All replies

  • do you have any other code in between the call to ScopeExists() and Apply()? it looks like something is resetting the ConnectionString value that's causing it to reset the connection string values.

    Wednesday, April 11, 2012 1:51 AM
    Moderator
  • No. And the password gets dropped whether it is true or false. Just checking to see if the scope exists drops the password.
    Wednesday, April 11, 2012 7:45 PM
  • you can stick with your solution of just providing the password again or try setting Persist Security Info = true in your connection string.
    Thursday, April 12, 2012 1:48 AM
    Moderator
  • I've seen this before. I can't recall exactly where this would happen but I would notice a password, it hit a specific command, then notice the password removed from the connection string in the debugger. It would happen consistently without fail.

    Pouring through the code again, but failing to recall exactly from memory I want to say Persist Security Info is the issue. I used "Database SyncSQL Server and SQL Express N-Tier with WCF" as my base sample and the helper classes it uses does not set this. I don't recall this happening in my testing without using WCF. I did a simple local database to database sync with seemingly no issues, though I may not have bothered using the helper then.

    I found it odd that sync clients would dictate server (peer) connections so I stripped that part out in favor of storing it internally in app/web.config and encrypting it. The only reasoning I could come up with MS including it was to keep the service agnostic and have the client dictate the endpoints.

    Friday, April 13, 2012 12:38 AM