Partially offline app using OA and caching

Thread is closed for posting
7 posts, 1 answers
  1. Dennis Gundersen
    Dennis Gundersen avatar
    23 posts
    Member since:
    Dec 2009

    Posted 05 Mar 2010 Link to this post

    Hi

    I have a solution with three projects, Entities, WebApp and WinApp. I found a video that shows how to implement syncronization using a local database cache and it looked really easy (doesn't it always ;-), but I can't figure out how to use OA with this.

    Is there an easy way to change the connection in Entities back and forth so that it gets data from the local sdf file for the WinApp if there's not network available, and from the SQL server for the WebApp? I'd prefer not to have two different solutions with copies of the Entities project as they're bound to become unsynced.

    TIA!

    Re
    Dennis
  2. Answer
    IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 05 Mar 2010 Link to this post

    Hi Dennis,

    I am not sure if I understand your question/architecture correctly, but one way to achieve it could be to modify the scope provider (the one that creates the ObjectScope instance for you, and thus the Database instance, too).. The idea is to have two connection ids which can switch at runtime depending on if you're online or not.

    I think I have seen a sample of how this is done on the Telerik site

    Regards

    Henrik
  3. Dennis Gundersen
    Dennis Gundersen avatar
    23 posts
    Member since:
    Dec 2009

    Posted 05 Mar 2010 Link to this post

    As I understand it, your suggestion is to create two connection strings and then basically check "if online then use id1, else use id2". That's clever, and I believe I've seen a Telerik video on that. Maybe it can be combined with some compilation directives so the WinApp is offline by default.

    I've also found that part of my problem is that the synch wizard added two date fields to the sdf that is missing in the mdf.

    Thanks.

    Re
    Dennis
  4. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 06 Mar 2010 Link to this post

    Yes,

    That's is exactly what I am suggesting. See if it suits your needs.
    We have a scenario like that in our WCF based solution and smart client front end. The Smart Client caches commonly used data contracts (from the WCF services, for example: country codes, currency codes, etc..)..  When the Smart Client needs information it talks to a Service Agent... This service agent has logic built-in on how to deal with the cache or go to the WCF service to get a fresh set of information if the cache is out-dated..  I think this concept can easily be transitioned to handle online-offline capabilities, too..

    Regards

    Henrik
  5. Dennis Gundersen
    Dennis Gundersen avatar
    23 posts
    Member since:
    Dec 2009

    Posted 06 Mar 2010 Link to this post

    Hi

    I found a video that shows how to change connection strings at both runtime and compile time through properties. It's not Telerik, so I'll include the link below.

    http://windowsclient.net/learn/video.aspx?v=13409

    Re
    Dennis
  6. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 15 Mar 2010 Link to this post

    Hi Dennis Gundersen,

    As Henrik already said, you can have two connections defined and obtain the object scope based on the name of the connection that you need:
    IObjectScope scope = null;
    if(workOffline)
    {
        scope = Database.Get("DatabaseConnection1").GetObjectScope();
    }
    else
    {
        scope = Database.Get("DatabaseConnection2").GetObjectScope();
    }

    The configuration in the App.config would look similar to this:
        <references />
        <connections>
          <connection id="DatabaseConnection1">
            <connectionString>Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
          <connection id="DatabaseConnection2">
            <connectionString>Data Source=.\SQLEXPRESS;Initial Catalog=NorthwindOA;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping">
          </mapping>
        </mappings>
    </openaccess>
    Hope that helps.

    Greetings,
    Alexander
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 15 Mar 2010 Link to this post

    Hi Alexander,

    Thanks for supplying the example. Precise what I had in mind.

    Regards

    Henrik
Back to Top