Wednesday, July 02, 2008
Posted on Wednesday, July 02, 2008 12:00:37 PM (Mountain Daylight Time, UTC-06:00)  Comments [0] | 
Categories: .NET | Fundamentals | SQL Server | Virtual Earth

A reader recently asked me to expand upon the "Keep it Simple" advice in the fundamentals section of my web site. Just like my advice, I had kept this section pretty lean...

Keep it simple

Anybody can build complex software. Creating simple software that can accomplish the same task is much more difficult. In the end though, the simpler it is, the easier it is to test, which makes it easier to maintain, and easier to extend.

To illustrate the idea, I'll talk about a project that I'm working on right now. Basically I'm helping / mentoring a team through a short term project to build a data viewer application based on Virtual Earth, Dojo, ArcGIS Server (9.2) and ASP.NET.

One of the user stories in this project is:

As an administrator I want the Data Viewer to be database agnostic so that I can easily configure it to pull point data from SQL Server, Oracle or file based data sources.

Now, this is a great idea, and certainly possible. In fact it ends up being very interesting to design (plug-ins, configuration sections and Inversion of Control oh my!).

Simple works...

In looking at the project (it's very short term) and the team (new to web development) and the current problem they are trying to solve (display data from SQL Server), my recommendation to the team is that we "keep it simple" for now, and just address the SQL Server data source.

While we could define a set of interfaces, build out a whole configuration model, and create the actual data access objects for these various data sources, in the context of this project it's extraneous. To be "successful", we need to display the current data in Virtual Earth. With tight time frames and limited resources, I believe the tradeoff between building for an unknown complex future need, and applying time and effort to the core objective, is a good one. The team will be able to get the database access tier of the system completed in a short time, and it will be very simple to understand - parameters are passed to a class, which calls a stored procedure, which returns the point data. Simple, clean, and working.

But what about the "can accomplish the same task" bit? Good question - I'd suggest that in this situation, with the current data is in SQL Server, you are doing the same task - just using a simpler design to achieve the goal.

Add Complexity when it is Needed

If / when a need arises to add data from Oracle, it will be a very simple task to create another class which mimics the SQL Server class, with the only difference being that it uses the Oracle data connection classes. Should this Data Viewer become a huge hit, and is used so extensively that it must become configurable by non-developers, it could then be refactored to add in the additional complexity required to support configuration sections and a plug-in data provider model. But for now, the much simpler solution works just fine.

So - to summarize: Make choices which trend towards keeping the code as simple as possible. Don't add extra features or design elements to handle unknown or fuzzy future requirements. Add complexity only when it's really needed. While it's fun to monkey with internal design optimizations etc, keep your eyes on the prize: software that works for the user. And keep in mind who will be maintaining the software over the long haul - while you may be a whiz at generics (for example) keep in mind that for many people they tend to make understanding the code more difficult.

That's pretty much my take on this, but I'd love to hear your thoughts on keeping software "simple". How do you decide when to add complexity? How do you define complexity?

Other thoughts on Simplicity:

Joel On Software: Simplicity

The Fourth Law of Software Design: Complexity vs. Ease of Maintenance

Various Quotes on Simplicity in Software Design

Friday, November 02, 2007
Posted on Friday, November 02, 2007 3:15:48 PM (Mountain Daylight Time, UTC-06:00)  Comments [0] | 
Categories: ArcGIS Server | ArcSDE | SQL Server
Our EDN licenses expired on Oct 30th and while I knew this was coming, I did not get to installing our new 2008 licenses until they had timed out on our ArcSDE server(s).

While you can use the ArcSDE Post Install tool to authorize ArcSDE using your new keys, if you have more than a few databases, it's much faster and easier to apply the license manually. (I have >10)

The license information (at least for SQL Server) is stored in the SDE_Server_Config table. Just copy arcsdeserver line of your ECP file (looks something like this: arcsdeserver,92,ecp123457890,30-oct-2008,S0M3H45HTH1NG) into the CHAR_PROP_VALUE column for the AUTH_KEY row.

Alternatively you can use this sql:

UPDATE    SDE_server_config
SET char_prop_value = 'arcsdeserver,92,ecp123457890,30-oct-2008,S0M3H45HTH1NG'
WHERE     (prop_name = 'Auth_Key')

If you have 100's of databases, get crafty with some T-SQL to iterate over all the databases and run the query...


Friday, September 07, 2007
Posted on Friday, September 07, 2007 2:50:55 PM (Mountain Daylight Time, UTC-06:00)  Comments [1] | 
Categories: .NET | ArcSDE | SQL Server

I ran across a very handy open-source tool today that I thought I'd share... but first some background...

Our current project requires that we support 4 simultaneous run-time configurations - Development, Testing, Training and Production. The application has the capability to switch between these on the fly, via  a convenient pull-down menu. 

dbp_switch_config

Changing the configuration is actually somewhat simple - we just close the current map document, set a new "repository connection" and refresh the UI. From there, the application will start using the configuration in the active repository. Great.

Well, today I needed to actually create these 4 repositories. More specifically I needed to create 4 databases with the same schema AND the same data (as a starting point anyhow). In the past I had used a CodeSmith template that would write out both the schema and all the insert statements to re-populate it, but that was a pain to use. I did a little searching and found the Database Publishing Wizard which is a part of the SQL Server Hosting Toolkit on CodePlex (you can get the source!).

From the site...

The tool supports two modes of deployment:

  1. It generates a single SQL script file which can be used to recreate a database when the only connectivity to a server is through a web-based control panel with a script execution window.
  2. It connects to a web service provided by your hoster and directly creates objects on a specified hosted database

For me, I just needed the SQL script that would re-create the entire database with data. What's nice (besides being free) is that this integrates into Visual Studio's Server Explorer...

dbp-vs-integration

The the output is a text file with all the SQL to re-create the tables, views, stored procedures etc. and their contents. I was able to just drop this into SQL Management Console, and run it against the other 3 databases. Since it's just T-SQL, I can also upload it to our client's site, and run it there to populate their databases as well.

Command Line

A final gem in this tool is that it can be run from the command line - thus allowing you to effectively source control a database schema and data. While you would not want to do this for spatial data, it would work very well for configuration data. You could write a simple MSBuild script that would check out the copy from source control, use this tool to dump the database to that file, and then check it back into source control. Then you could execute this script anytime you want to update the copy in source control. Anyhow - the command line give you lots of options for integrating into your development process.

Wednesday, October 25, 2006
Posted on Wednesday, October 25, 2006 10:13:11 AM (Mountain Daylight Time, UTC-06:00)  Comments [0] | 
Categories: ArcSDE | SQL Server
If you have installed SQL Server 2005, and run into a COM error when opening Managment Studio that looks like this:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.OLE.Interop.IServiceProvider'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6D5140C1-7436-11CE-8034-00AA006009FA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

the fix is a registry hack: (provided by Nicolas Buse on the MSDN forums)

I've pasted the registry section below as much for my reference, as to have another place on the net to locate this little gem. Hope this helps!

[Copy from HERE]
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}]
@="IServiceProvider"

[HKEY_CLASSES_ROOT\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\NumMethods]
@="4"

[HKEY_CLASSES_ROOT\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\ProxyStubClsid32]
@="{B8DA6310-E19B-11D0-933C-00A0C90DCAA9}"

[HKEY_CURRENT_USER\Software\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}]
@="IServiceProvider"

[HKEY_CURRENT_USER\Software\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\NumMethods]
@="4"

[HKEY_CURRENT_USER\Software\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\ProxyStubClsid32]
@="{B8DA6310-E19B-11D0-933C-00A0C90DCAA9}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}]
@="IServiceProvider"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\NumMethods]
@="4"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{6D5140C1-7436-11CE-8034-00AA006009FA}\ProxyStubClsid32]
@="{B8DA6310-E19B-11D0-933C-00A0C90DCAA9}"

[ ... TO HERE]

Simply copy the above text, and put it into a text file with a .reg extension. Then double click the file and click yes on the resulting dialog box.