Tables are not created on client data store when sync code is executed but, no errors are thrown. RRS feed

  • Question

  • I am implementing an N-Tier architecture for a remote sync scenario. My client, which is a WPF desktop application is attempting to sync with a SQL Server database using a WCF web service I have written. The sync code is executing without error but, no tables are being created on the local data store, which is a SQL Compact Edition database. I am at a loss as to how to debug the problem. I am following the example shown here:


    I have been over my code many times, and I can't find anything in the example that is not in my code (I haven't left anything out). I have commented out the code that creates all the SyncTables, except one so I can try to test the simplest case.

    In the client-side code, in my class that extends the SyncAgent class, I have created an event handler for the SchemaCreated event. If I put a breakpoint in this event handler I can see that the table schema is being created as it should, but the table is never added to the database.

    Here is an example of how I am creating the synctables in the client-side SyncAgent class:

    SyncGroup grpDownloadOnly = new SyncGroup("DownloadOnly");

    SyncTable mySyncTable = new SyncTable("MyTable");
    mySyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable; 
    mySyncTable.SyncDirection = SyncDirection.DownloadOnly;
    mySyncTable.SyncGroup = grpDownloadOnly;

    When I examine the SyncStatistics that are returned by the call to this.Synchronize(), it reports that the appropriate number of records were created. (DownloadedChangesApplied = 122, which is right. DownloadedChangesFailed = 0).

    But, if I go to the Server Explorer window in VS, and look at db.sdf under DataConnections, there are no tables listed. Refreshing the file doesn't help.

    Can anyone suggest what I might do next to debug this problem?

    Thanks for whatever help you can provide. 

    Tuesday, October 4, 2011 1:57 PM


  • are you sure you're looking at the right SDF file? check you application's bin folder if there's an SDF there.
    • Marked as answer by rknowles Tuesday, October 4, 2011 7:04 PM
    Tuesday, October 4, 2011 2:14 PM

All replies

  • are you sure you're looking at the right SDF file? check you application's bin folder if there's an SDF there.
    • Marked as answer by rknowles Tuesday, October 4, 2011 7:04 PM
    Tuesday, October 4, 2011 2:14 PM
  • Thank you for your reply.

    I checked the bin folder...nothing there but the Debug and Release folders, and there is no .sdf file in either of those.

    I also tried to connect to the database from my code, after the sync code has executed. I can make a connection but when I try to ExecuteReader on a SqlCeCommand object with a query like "SELECT * FROM MyTable". A null object is returned. So, I have verified that the Table is not being created (I was hoping the table was actually there, but not showing up in the explorer for some reason). 

    CORRECTION: The null object error is being generated after the testing code has executed. So the problem is not with accessing the table...see my second post, above.

    Thanks again.

    • Edited by rknowles Tuesday, October 4, 2011 3:12 PM
    Tuesday, October 4, 2011 2:39 PM
  • can you post the sync code here? did you by any chance just copied and pasted bits and pieces from the completed code samples?

    the fact that your sync statistics displays it has applied changes means it has created the tables.

    • Edited by JuneT Tuesday, October 4, 2011 3:10 PM
    Tuesday, October 4, 2011 3:07 PM
  • After further testing:

    I put the following code in the client application to test the synchronization:

                int num = 0;
                using (SqlCeConnection conn = new SqlCeConnection(@"Data Source='db.sdf'"))
                    using (SqlCeCommand comm = new SqlCeCommand("SELECT * FROM MyTable", conn))
                        SqlCeDataReader reader = comm.ExecuteReader();
                        while (reader.Read())

    If I place the above code directly after the call to Synchronize the data, it runs without error, and the variable "num" contains the correct count for the rows in the table. After the synchronization code has run the application experiences an error. If I then move the code above to a place before the synchronization code runs, and run the application again, I get an error stating that the table can't be found. So it appears that the sync code runs correctly but, because an error is experienced after the sync code executes, the table is somehow lost. I could understand this behavior if an error was encountered DURING the sync process but, I don't understand why the table is lost after the sync code has executed. 

    I will continue digging into this and post my findings. If this sounds like a familiar scenario to anyone, I would really appreciate your observations and comments.


    Tuesday, October 4, 2011 3:11 PM
  • i suggest you check your code if there's anything that's deleting and recreating the sdf after the sync.
    Tuesday, October 4, 2011 3:14 PM
  • OK. 

    More observations:

    I DID find another copy of the database in the bin\Debug folder! It does not show up in the Solution Explorer in Visual Studio but, if I right-click on the bin\Debug folder and choose "Open folder in Windows Explorer" then, I can see the db.sdf file.  I haven't yet found a way to make the db.sdf file visible in the Solution Explorer. This is unfortunate behavior, to say the least.

    Anyway, that db.sdf file is not having the table added to it either. It is behaving the same as I described before. If I put a breakpoint in the testing code I posted earlier, where the query has returned the correct result set and, while the code is paused, I query EITHER version of db.sdf to see if there are any records, I get the "table cannot be found error". Perhaps there is yet another copy of the database that has been created somewhere that is the one actually being used?

    I don't know. This is almost funny.

    So, to recap. I found another copy of the database in the bin\Debug folder. But it does not have the table added to it when the sync code is run, either. If I query either copy of the database (the one in the root folder of the app, or the one in the bin\Debug folder), I get the "table not found" error. But the code seems to be adding the table correctly, and without error. 

    Tuesday, October 4, 2011 6:53 PM

    OK. The project I have been working in is a library that contains the Model classes, Command classes, and other supporting classes for a WPF project. This project is one of two projects in the solution I am creating. The other project has the WPF files that represent the interface of the application. That project does not show a bin folder in the solution explorer at all but, if I use Windows explorer to look at the files, there is a bin folder there. It contains ANOTHER db.sdf file (three files for the price of one!) and THAT file is the one that is getting the table added to it.

    So, I just have to figure out how to access that file from the Core Libraries project, or prevent that file from being created, and using the one that I thought I was using the whole time, or something. 

    Good grief.

    Nothing is easy. And NOTHING is as it seems. 

    JuneT. Thank you for your VERY helpful suggestions. You pointed me in the right direction...it just took me a while to realize it.

    Thanks very much.


    Tuesday, October 4, 2011 7:04 PM