Disconnected mode?

Disconnected mode?

Old forum URL: forums.lhotka.net/forums/t/62.aspx


ajj3085 posted on Wednesday, May 10, 2006

Hi all,

I was wondering if anyone here implemented an application which can work while disconnected.  The exact scenario is that our sales people should be able to look up customers and work on quotes even while they are on the road with their laptop.  Preferably, the laptop would accumulate changes until its docked back into our main network again.

Any suggestions? I've been thinking of using Sql Express on the laptop with transactional replication and updateable subscribers.. and then figuring out if the main server is available.

Thanks
Andy

RockfordLhotka replied on Wednesday, May 10, 2006

That is my recommendation - either use merge replication between the databases, or create a sync agent that runs on the client and calls a set of services on the server (which really means you are writing your own merge replication in a sense).

The thing to recognize up front is that you are essentially writing or creating 3 different applications:

  1. The client application that runs entirely against the client database
  2. The sync application that is responsible for moving data to/from the client and the server
  3. The server application which runs entirely against the server database (or other back end resources - honestly it is outside the scope of an occasionally connected discussion for the most part)

Recognizing that you have these three, essentially separate, applications to deal with is (I think) the critical step to success.

CSLA101 replied on Wednesday, May 10, 2006

I must have given my client some bad advice. I followed SerratedBobCat's advice to look into the dataset diffgram (my client isn't using CSLA and that wasn't an option). My boss came by and started drawing something similar to what you suggest on the white board... MSDE/SQL Server Express on the laptop with mirrored schema... and some form of resync back with the base server dbms. My initial thought was that the dataset surely offers some assistance in this area, although I had not heard of diffgrams. SerratedBobCat pointed me in the diffgram direction, and I built a demo disconnected application (which I will attach). The demo offers two paths... 1) saving the intermittent disconned session saves (diffgrams) to file OR 2) to a blob. In production the laptop user would "check out" the data they would work with offline (not thrilled about manual locking schemes, but if you are careful, it can be done in some circumstances). Then the user can iteratively (retrieve from disk/blob... save back to disk/blob) disconnected until a point they are read to check back in to the mother ship dbms. So the diffgram provides both the disconnected mainteance and the input to update via dataset back to the base dbms. It certainly seems infinitely easier than resyncing two seperate schema UNLESS I'm missing something, which is entirely possible (I only created the proof of concept demo, and haven't put this into production). Also, one might have certain requirements ... like laptop disconnected audits of some sort which would require a dbms, and then you would have to go the resyncing route. I'm here to learn... so if there are pitfalls to know about with the dataset diffgrams, let me know... I'm likely to be the one to develop that disconnected feature in our application at a later date.

I'm attaching the demo for anyone that is interested. I was new to memory and filestreams, so I don't claim the code is efficient. The real point of the demo is a proof of concept on disconnected mainteance using diffgrams. The sln is a VS 2003 app (that's what the client is using on this application). There is a readme in the database project folder that explains how to get up and running... you just need two VERY simple tables. Also note, there is connection string literals at the top of form to set once you have setup your two tables.

I will check in later and give more feedback if anyone is interested in the app. Also, everyone please give any feedback on the sidebar issues... like maybe better coding techniques for going from dbms to winforms and vice versa. Same for files.

Oops... where is the attach option? I will come back and do this... have to run.

 

 

 

 

 

CSLA101 replied on Wednesday, May 10, 2006

Can we attach file here? I'm not seeing it. I was hoping for a reserved non-scrolling place in this new forum for posting sample code, articles, sample/demo applications, CSLA design tips, etc. If that's not a possibility, I was going to suggest we just create a post in this new forum titled something like "Demo apps and Sample code"... and we could all just post that type of sharing in the same thread. We would all get used to searching for that individual thread. I found the old forum frustrating because you knew there was a wealth of knowledge there... but it would be very easy to miss it by relying on search. For example... I saw Andres posted a great tip about Winforms and generics... and that will just disappear in the CSLA vapors.

Anyway... I posted the "Offline Maintenance" app I mentioned above on the old forum here. I ended up using the term "Offline" mainteance rather than disconnected because aren't all n-tier apps disconnected (other than winforms non-remoted traditional client server).

So back to the discussion.

First prc... man I would certainly hope you had the option to provide some form of "locking at checkout" on the base dbms. Writing one of those home grown replication/merge things seems like a potential maintenance nightmare. You sure would want to make sure there is enough $ upside to warrant the "non-locking plus multiple merge mini-dbms engine" object. Big Smile [:D]

Now... still playing devil's advocate... why would folks pick a mirrored laptop schema / merge path rather than the dataset diffgram. The idea would be the entire table structure and it's relationship would be housed in the diffgram... and that's the basis for the updates back to the base dbms. This seems infinitely better than laptop dbms intallation, schema updates mirrored from base dbms, etc. There would obviously be some applications that would require more functionality (user CRUD audits captured on the laptop.. i.e. audits beyond the diffgram table relationships), and that might require one to move beyond the diffgram. Even then... couldn't one include those laptop user offline audit table requirements to the base dbms, and include the audit tables in the check out? Save the diffgrams to file... or to a simple row blob column (yeah... you would then have to install the MSDE or SQL Server Express.. but a simple table definition ... don't have to keep up with dual schema maintenance).

Now if you were a CSLA shop... why wouldn't you use the CSLA BO as the diffgram equivalent... and serialize the BO (and it's associate object graph) to file or to dbms blob. Again, it would seem infinitely easier to apply the offline BO saved state back to the base dbms... with the built in CSLA plumbing rather than try and do a dbms->dbms resync/merge.

Interesting ... this seems to be a fairly common application need out there.

btw... if anyone actually tries to run the app I posted on the old forum and has trouble, let me know. It's pretty simple ... just start with the readme in the dbms project create script folder.

SerratedBobCat... are you out there. Chime in on your diffgram usage.

 

 

 

  

 

 

pelinville replied on Wednesday, May 10, 2006

I am SeratedBobcat!!!! (well, used to be in the bad place)
 
We built a CRM package that had to tie Microsoft Great Plains and ACT! together. Our Great plains DB had about half a million customers and was about 30 gig or so in size.  The sales rep needed to have anywhere from 1,000 to 7,000 customers with associated sales history and other data.  The ACT! sdk was used to get the data into and out of ACT! itself but the data was stored in a couple of datasets. There where some .NET applications that where launched when certain events happened in ACT!. The biggest offline datasets where about 50 meg total.
 
Here are some of the issues we had to contemplate and overcome.
 
1. Amount of data needed by the disconnected client is the first and potentially largest obsticle.  Datasets are not in the same league of even an MS Access database when it comes to managing large amounts of data.  So if the user has need for a very large amount of data then SQL Express (or some other client RDBMS) may be your only choice.  But the key is "has need".  Looking at the reps usage showed us that they only used about 1/20 of the data available.
 
Even so with a bit of work the performance was fine.  Things like turning off the datasets EnforceConstraints when loading and breaking the tables into different datasets then only loading them when needed and on different threads.
 
2. Security of data.  Datasets are not secured so you have to do that yourself.  Our data wasn't very sensitive so most of them where simply tied to a secondary user through the windows security features.  What data did need protected was encrypted. This hurts performance, of course.
 
 
3. Who wins when updating the data.  This one sounds trickier than it really is. The fact is even normal apps that use disconnected data has the exact same problem.  It is just with offline apps the number of conflicts gets bigger. One thing that can mitigate this is  setting rules of who owns the data. For example in our case the sales reps owned all the customers contact and descriptive data. If they made a change that change was persisted to the corporate data.  Corporate had control over all sales data and inventory. If corporate data differed from the reps it "won" and the rep was notified of what changed. 
 
In one or two cases a business rule had to be modified to account for the disconnected nature of the application.  One was something like "Can't create a quote with a discount for a customer with a overdue account".  This had to be changed to "can't create an order from a discounted quote for a customer with an overdue account".  Sounds simple but caused a big 'ole rucus between sales and accounting.
 
In the end the power accorded to the sales reps far outweighed the business rule changes needed. 
 
4. Data corruption.  The datasets are just plain old files.  Deletes happen because users sometimes do silly things. You have to have a plan to replace those files that preserves as much data as possible.  Many DB's protect against inadvertent file deletion.  We solved this one by creating a user on the reps machines that controlled the data and impersonating that user in the application.  If you don't have that kind of control something else has to be done.
 
We initially persued the MSDE syncronized with corporate data option.  That presents it's own problems.
 
A. The support staff has to know MSDE or whatever DB system you use.  It is ALOT easier to replace some dataset files if something goes wrong than it is to re-create a DB Schema.  And with a data set you can always open it up and read it like a text file to find out what could be wrong.
 
MSDE had no client app to manage it that I remember. SQL express has one so that may not be a factor.
 
 
B. Consider item 3 above.  If there are complex business rules to work out during sync doing it in the services provided by a RDBMS is very hard if you don't have a DB guru around.  We had one for SQL server but not one for the database ACT! used. And even then our DB admin didn't have the time to implement the rules we had to check.
 
C.  The syncronizing couldn't be done over port 80.  Or any port for that matter. Our DBA refused to open it to the world.  And our reps couldn't always run the app from a computer that could establish a VPN.  Also with diffgrams you could zip them up, send them through a web service and the amount of data transfer was almost nothing. Most never exceeded 40k because xml zips real nice.  Even simple sync using SQL was magnitudes larger. When some of your clients might be forced to used dial up this can be a very important factor.
 
 
One other thing to note is that using a DB requires a more complex install. No xcopy deployment.  In fact we where able to put the app on a thumb drive and run it from any computer with .NET framework installed. And we even had the .NET framework installer on it so it could be run from almost any computer. Can't do that when using MSDE system.

CSLA101 replied on Wednesday, May 10, 2006

SeratedBobCat to pelinville. I'm going to have to start a xref. :)

Hey... thanks for the long post. You raised some interesting points... including the size of the datasets/diffgrams. In my company's case, I believe the row counts would not be an issue. What might be an issue is any limit that is reached on tables/relationships in A dataset... and like you said, you could always split them up. I tested a very simple scenario (one table)... and I knew I would need to further test the diffgram updates when they housed relationships (i.e. parent - child). In theory... it's all just table updates, so it should work fine.

Note: my choice was dataset + dataset widgets OR laptop dbms + merge back to base dbms. CSLA was not an option. Would you agree you could do the exact same thing with CSLA BOs that you did with diffgrams? It sounds like you were saving the diffgrams to disk... i.e. not to laptop dbms. Actually, the CSLA undo feature seems like it might serve many offline needs very well... i.e. offline setup, profile creation, etc...  

In the n-tier world where most apps are disconnected... the plumbing is pretty much the same whether you update that disconnected data in 5 minutes or 2 days (with some intermittent BO saving to disk).

 

prc replied on Wednesday, May 10, 2006

Rocky's comments tally with my own experiences.  We have just released an application where winform clients run against an MSDE database and synchronise via a web service with an Oracle DB.  User's had to be able to edit records on either DB and the winform client can also run against the Oracle DB when suitable connections are available.

Because of the difference in DB platforms, we ended up writing our own replication system.  Don't underestimate the work involved in doing this! 

The biggest problems occurr when there are business rules that span related tables, e.g. a value in table A determines what valid values are in table B.  What happens if someone edits the value in table A on one database whilst at the same time, someone else is editing values in table B?  If you aren't careful, whilst synchronisation may not break any database constraints, business rules may be violated.  Do you implement business rules in your database with triggers, etc.?  Or do you restrict what the user can do so that you reduce the risk of rules being broken?  I don't think there's an easy answer.

I don't want to put you off - we're just starting on a new application with a similar architecture so it hasn't deterred me Wink [;)] - but be aware of the pitfalls

cheers

Paul

CSLA101 replied on Wednesday, May 10, 2006

prc...

Question: why MSDE and not SQL Server Express. My client had MSDE in the specs also... but planned on approaching the client with a change to SQL Server Express. Of course we had the luxury of starting from scratch... you may not.

 

prc replied on Saturday, May 13, 2006

We started this two years ago so SQL Server Express wasn't an option then.  I would go with it now though

glenntoy replied on Thursday, May 11, 2006

If you are not an expert on database replication or your organization doesn't have an expert DBA doing replication, I suggest you create your own replication as what Rocky has suggested.

Creating your own merge replication does have a cost in development but in my own opinion you I prefer that way than going to DB replication and you don't have experience in doing it.

ajj3085 replied on Thursday, May 11, 2006

Thanks for the great replies everyone.

I did think about serializing the BOs while the app is offline and then saving them all when its back online.

Fortuantly things are a bit easier for me re: the Sql Express route; the support staff is myself and a single IT tech.  Our sales team consists of two people, one of which doesn't travel I believe.  I'll investiage the Merge replication route before I attempt my own custom sync solution.

pelinville, its funny you mention ACT.  The app in question is actual a custom replacement for ACT; they don't want to pay for an upgrade (they want the freedom custom apps provide, and dont' use 99% of the features in ACT) and they also would like other applications replaced, the goal being much better integration between them (they aren't impressed with the intergration of the off the shelf software).

Thanks again for the replies.. definatly will look into the sample and various options provided.

Andy

ajj3085 replied on Thursday, May 11, 2006

One more thing for Rocky..

Are those three bullet points only if I go an write my own merge manager, or did you mean they apply regardless of which route I go?

Thanks
Andy

RockfordLhotka replied on Monday, June 19, 2006

ajj3085:
One more thing for Rocky..

Are those three bullet points only if I go an write my own merge manager, or did you mean they apply regardless of which route I go?

Thanks
Andy

I mean they apply regardless. The only difference is that your sync "app" might be a database replication technology instead of an actual application. But even in that case, you will likely end up writing some sort of code to deal with data collisions that can't be resolved automatically - and that is part of the sync app.

ward0093 replied on Saturday, May 13, 2006

We have an entire application solution here designed around this exact senerio... All our clients run actually in Disconnected mode... and (like Rocky mentioned) we are currently designing our Syncronization Tool (a service that will run on the client machine) and syncronize all the databases with the central database system.

Jan replied on Saturday, May 13, 2006

Hi,

Just wondering why no-one is mentioning the soon available "SQL Server Everywhere", which is in fact "SQL Mobile", but also useable on the desktop versions of Windows.  It's lightweight and should both support clickonce deployment and merge replication.  Have a look at http://blogs.msdn.com/stevelasker/archive/2006/04/10/SqlEverywhereInfo.aspx .  To me this looks as the perfect solution for disconnected cases, with clients running on Windows based laptops.  Looking forward to your opinions / comments.

Regards,

Jan

CSLA101 replied on Saturday, May 13, 2006

It would seem the design needs of this topic "disconnected / offline mode" would be dependent on the scope of the "offline needs". If the entire application needs to be available disconnected/offline, then one would lean toward replicating (and double maintaining) the entire schema on the disconnected clients. However, if you were talking about a narrow scope of the application required in disconnected mode, which could be provided by division of labor/data in a check out fashion (i.e. lock down the data that was checked out) and simple disconnected diffgram management (or disconnected CSLA BO management) on the client PCs, then signing up to maintain schemas and a dbms on all of those client machines seems like a maintenance mistake/overkill... even if tools like SQL Server Everywhere make it easier (haven't read the link yet). Of course, there are tons of grey between those two extremes... and many ways to skin the cat.  

CSLA101 replied on Sunday, May 14, 2006

Jan,

Hey, thanks for the SQL Server Everywhere (SQL/e) link... I just read it. That's some very good information. Jeeze... you are reminded why Rocky says code defensively against the Microsoft data connection technology and widgets (sounds like SQL/e isn't ADO.NET... at least not yet). Also important to note that SQL/e doesn't support procs or procedures... so you sure would want to know that ahead of time in your design. Sounds like they aren't planning on XCOPY deployment... ?? Anyway, good information. SQL/e and SQL Server Express are two different products... and I guess for two different purposes (don't know about that one, seems like we only needed one client side dbms rather than two). The current project I'm on that will need some disconnected functionality has mainframe zOS DB2 7.1.2 as it's dbms. We refer to it as the MF database... and MF doesn't stand for mainframe if you get my drift. :) I don't think we will be automagically merging SQL/e data to mainframe zOS anytime soon. :)

The following is from the link... can anyone explain what this means.

Q: Can I use SQL/e data files as my application document format? 
A: Yes, SQL/e data files are pure data.  Unlike the server SKU’s, SQL/e doesn’t have any code. No sprocs, views, triggers, extended sprocs, macros or ability to run XP_CmdShell.  Because of this, we do consider SQL/e files a doc safe format. 

 

 

 

 

 

 

 

 

ajj3085 replied on Monday, May 15, 2006

CSLA101,

I read that too; sounds like it would be more work to use Sql/e over Express.  It also doesn't sound like it can do any replication, which is the route I'd rather start with.  I'll attempt Merge Rep with Sql Express since my app requires all functionality be present disconnected or not..

If we decide for sure to do this I'll certainly post back with the results. 

Andy

RockfordLhotka replied on Monday, May 15, 2006

SQL/e does merge replication, along with another type of light-weight replication designed for mobile scenarios.
 
The value of SQL/e over Express is that it doesn't require an extra install, and it is only 1.5 megs instead of the much larger Express install. In other words, it is far easier to get onto the client workstation than Express - and can even be used in environments where IT might say you can't install Express due to security concerns (it is actually SQL Server after all - running in its own process, etc.)
 
Rocky
 

kdubious replied on Wednesday, June 14, 2006

I just found this, after having posted a new similar thread.

I'm still torn between SQL Repl and my own custom code.  I understand the 3 app approach.  I wrote a bastardized CSLA hack a while back to do this whole thing in one app, and it got very ugly.  I manually configured remoting on the fly.

What I'm wondering is this:  How would I best load CSLA BO's from the local DB, then use the remote DataPortal to save them to the Server?

Thanks,

Kevin

Plain replied on Wednesday, June 14, 2006

 

Thanks all for a very useful discussion! 

Jan, thanks for the SQL Everywhere link. Very interesting stuff! Just one side note. SQL Express supports merge replication ONLY as a subscriber. What it means is that only the changes from the corporate side (assuming that corporate db is hosted by SQL Workgroup/Standard/Enterprise) can be merged into the client's db that is hosted by Express :(

See here for details: http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx

IMHO that was a very disconcerting change from MSDE 2000 that allowed (with certain limitations) Distribution/Publishing as well as Subscription modes. See here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q324992

This is actually one of the reasons our company considers using MSDE 2000 on clients instead of Express. We've had for years an optional (custom) sync module for our main app that we called "Laptop sync". This module allows agents on field do their job and bring it back to the main office to sync with the main db. I can tell you from the experience that the module has always been somewhat difficult piece of code to maintain. We are moving towards database replication for better maintainability. SQL Everywhere will be a great thing if - along with other good things - it allows merge replication as a Distributor/Publisher. :)

 

Plain replied on Wednesday, June 14, 2006

Just found this on the topic of SQL Everywhere CTP:

http://www.microsoft.com/downloads/details.aspx?FamilyId=85E0C3CE-3FA1-453A-8CE9-AF6CA20946C3&displaylang=en

Looks very good to me.

ajj3085 replied on Wednesday, June 14, 2006

Plain:
SQL Express supports merge replication ONLY as a subscriber. What it means is that only the changes from the corporate side (assuming that corporate db is hosted by SQL Workgroup/Standard/Enterprise) can be merged into the client's db that is hosted by Express :(

See here for details: http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx

IMHO that was a very disconcerting change from MSDE 2000 that allowed (with certain limitations) Distribution/Publishing as well as Subscription modes. See here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q324992

Plain,

Just want to point out that your definition of subscriber is wrong.  Changes DO propigate back to the publisher if you change the subscriber.  All that 'subscriber only' means is that OTHER database instances can't use the instance of Express as a publisher; basically you can't setup a master server using Express and have it publish to other instances of Express (and thus avoid buying any licenses for Sql Server).

Hope that clears things up.

Andy

Plain replied on Wednesday, June 14, 2006

Andy,

thanks for the correction. Yes, you are right and I was wrong about merge replication not updating the subscriber. To all: my apologies for the confusion in my previous message.

Copyright (c) Marimer LLC