Best update questions in October 2010

Automatic updating of C# programs

7 votes

I'm writing a suite of programs for client PCs --

  • a Windows Service
  • a user-space Windows Forms application

I need to be able to publish an updated version of these programs and have the client PCs automatically and transparently (with no user interaction) update themselves. This update will be done over an unreliable 3G connection (EvDO). The applications will be continuously running, so the update will have to gracefully shutdown the service / close the applications, and then spin them up again after the update.

Before I spend time rolling my own solution, are there any pre-existing solutions for something similar?

Note: ClickOnce doesn't work here because of the Windows Service as well as several other reasons. I also can't take advantage of BITS because I'm running against Windows Azure, which lacks the BITS IIS plugin.

Why not consider shadow copy.

Shadow copying enables assemblies that are used in an application domain to be updated without unloading the application domain. This is particularly useful for applications that must be available continuously, such as ASP.NET sites such as ASP.NET sites

Make the programs very simple shells. Then have them watch (FileWatcher) for updates to folder where they were loaded from (and where updates are delivered). Then dynamically reload the AppDomain.

See here and here for more info.

You can use the properties of the AppDomainSetup class as follows to configure an application domain for shadow copying:

Enable shadow copying by setting the ShadowCopyFiles property to the string value "true". By default, this setting causes all assemblies in the application path to be copied to a download cache before they are loaded. This is the same cache maintained by the common language runtime to store files downloaded...

What can cause 'rows affected' to be incorrect?

7 votes

Using Microsoft SQL Server Management Studio 2008. I have done a simple transaction:

BEGIN TRAN

SELECT ko.ID, os.ID AS ID2
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);

UPDATE table_b SET the_date=ko.the_date
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);

SELECT ko.ID, os.ID AS ID2
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);


ROLLBACK

So the SELECT and UPDATE should be the same. And the result should return 0 rows. But the UPDATE affects one row less than the SELECT gets from DB:

(61 row(s) affected)

(60 row(s) affected)

(0 row(s) affected)

What am I missing here?

I'd suspect the most likely reason is that Table_a in your example has a row with a duplicate ID in it - this cases an additional row to appear in the join in your first select, but the update only deals with rows in Table_b, so your duplicate row doesn't matter. This statement should give you the culprit:

SELECT ko.ID
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL)
GROUP BY ko.ID
HAVING COUNT(*) > 1