views:

84

answers:

2

Right now I have a Winform app with a SQL Server back end. The DAL is comprised of Linq to SQL. One of the complexities of this app is it's need to function offline.

I have accomplished this by using Merge Replication to keep there local SQL Express instances in sync with a central SQL Server. I have some logic that detects there connection state and switches the contexts connection string appropriately, like so:

partial class AspnetdbDataContext
{
    public static bool IsConnected
    {
        get
        {
            return Settings.Default.IsConnected;
        }
        set
        {
            Settings.Default.IsConnected = value;
            Settings.Default.Save();
        }
    }
    public static AspnetdbDataContext Create()
    {
        var cs = IsConnected ? Settings.Default.Central_aspnetdbConnectionString : Settings.Default.aspnetdbConnectionString;
        return new AspnetdbDataContext(cs);
    }
}

My question is thus, will this also work with Silverlight 4? In theory, I would detect when they are offline and switch the connection appropriately. Thoughts?


What about using something like this WCF Self Hosted Service Library? Could something like this be used to access a local SQL Express while "offline"?

+1  A: 

With Silverlight (any version) the problem isn't so much connectivity to the database. In Silverlight, you don't have it. The only thing you can do is make a call back to the server that the request originated from.

Because of this, you would have to have some sort of local IIS instance running and connect to that, which would then in turn connect to the local SQL instance.

The thing is, if your SL application was loaded from your site, and then connectivity was lost, your app couldn't detect it. You would have to go to a new link to the server on the local machine and then have them switch back when they have connectivity again.

For something like this, it's probably best that you stick with the Winforms app and determine whether or not you have connectivity there. That way, you can switch which database you hit when you don't have connectivity.

casperOne
Thanks for the answer. However, I thought that SL4 could do out of browser/offline? Are you saying it can't unless the original web server is available?
Refracted Paladin
@Refracted Paladin: Yes, you can do out of browser/offline, but you still have the same limitations. You can store data locally, but that's simply storage. You don't actually have database objects to work with. You need to connect to a server to do that, or store your data in some sort of parsable format which your app will upload later.
casperOne
@casperOne: so, can Silverlight, in OOB/Offline mode, connect to SQLExpress if I explicitly point it at it?
Refracted Paladin
@casperOne: sorry for being thick, I am just not following you at all. Your statement, "In Silverlight, you don't have it." is really throwing me for a loop.
Refracted Paladin
The Silverlight .NET Framework doesn't have the necessary bits of the class library (i.e. ADO.NET) to allow you to do anything on the client. That's the problem.
Craig Shearer
+1  A: 

What casperOne is saying is that out of browser Silverlight does not have access to a full fledged database on the client. The best that can be done is to use some sort of compact database either in the isolated storage or within one of the few accessible folders with Silverlight 4. I have personally used siaqodb.com , but you will have to keep the data synchronized manually (which can be a nightmare).

More recently I have seen someone get access to a SQL compact database. However, there could be more ways of accessing data now. It has been some time since I've looked for a client side database for Silverlight.

Fama