Question : SqlCeResultSets in Windows Mobile

I have a problem with a mobile piece I'm working on that involves several datagrids.  The selection made in the first datagrid drives the options that appear in a second, and so on until the user can get to the specific detail record they're after.  At any point, the user can back up to the original datagrid (or any they've already made a selection for) and change their choice, which clears the "child" selections which are then re-chosen.  In this case, all datagrids are read-only - any editing takes place on different forms.

My problem is that the program throws a "not enough storage" error the third time a parent selection is changed, which occurs during the query to get the new options for the child.  I've tried destroying the SqlCeCommand objects immediately, which messes up being able to pull selected IDs.  The next workaround I tried was checking them just before rebinding.  Data adapters and tables are not an option because of the overhead they generate.  It was my understanding (and experience so far) that SqlCeResultSet works much faster with minimal overhead, but I'm willing to try other options.  

The example code below has been altered to protect intellectual property, and is provided as an example.  Code details not provided include:
  • A persistent connection with the local database kept in myStaticGlobals

  • Synchronization with a master SQL server.  During sync the local connection is destroyed, and it is reinstantiated after the sync.

  • Datagrid events are wired/unwired through a helper class.

  • Selections are tracked in a custom class with parent/child relations and methods to manage the resulting stack.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
//*****
//TODO: unwire any event handlers that will be triggered by a rebind
//*****
GridHelper.UnregisterDatagridEvents(ref datagrid1);

System.Data.SqlServerCe.SqlCeCommand cmdSql = new System.Data.SqlServerCe.SqlCeCommand();
cmdSql.Connection = myStaticGlobals.LocalConnection;
System.Data.SqlServerCe.SqlCeResultSet ceResults = null;

SelectedContext visitContext = myStaticGlobals.SelectedData.FindContext("Visit", false);

if ((visitContext.SelectedId == null) || (visitContext.SelectedTable == null))
    MessageBox.Show("No visit selected.");
else
{
    cmdSql.CommandText =
        string.Format("select column1, column2 from table1 inner join {0} as visits where visits.id = {1}", visitContext.SelectedTable, (Int64)visitContext.SelectedId);
    ////TODO: add DataGridStyle?

    try
    {
        if (this.datagrid1.DataSource != null)
        {
            ((System.Data.SqlServerCe.SqlCeResultSet)this.datagrid1.DataSource).Close();
            ((System.Data.SqlServerCe.SqlCeResultSet)this.datagrid1.DataSource).Dispose();
        }

        ceResults = cmdSql.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable | System.Data.SqlServerCe.ResultSetOptions.Insensitive); //<-- error thrown here
        this.datagrid1.DataSource = ceResults;
        
        this.datagrid1.TableStyles.Clear();
        DataGridTableStyle hideId = new DataGridTableStyle();
        this.datagrid1.TableStyles.Add(hideId);
        hideId.GridColumnStyles[0].Width = -1;
    }
    catch (System.Data.SqlServerCe.SqlCeException exSql)
    {
        if (exSql.Message.IndexOf("not exist") > 0)
            MessageBox.Show("Please re-sync all device data.");
        else
            MessageBox.Show(exSql.Message);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
//*****
//TODO: Re-wire any event handlers for trickle-down effect and fire them
//*****
GridHelper.RegisterDatagridEvents(ref datagrid1);

Answer : SqlCeResultSets in Windows Mobile

Windows Live OneCare has been discontinued on 30.6.2009 and and has been built on RAV technology. Successor is Windows security essentials - a freeware tool. In short OneCare it is history...
I quite often use antimalware (or shortly MBAM) from Malwarebytes - a freeware version. This version does not have realtime scan, but it is quite effective against all sorts of malware.
Random Solutions  
 
programming4us programming4us