Monday, March 24, 2008

IIS7: Unable To Create The Default Provider...

I had a bizarre problem with IIS7 the last couple of days that had just about driven me to drinking...and now am happy to post a solution. 

The problem came when I needed to delete a virtual directory.  Simple enough, right?  Not so!  For some reason every time I went to delete a virtual directory IIS7 gave me this very unhelpful error:

---------------------------
Internet Information Services (IIS) Manager
---------------------------
Unable to create the default provider, make sure the default provider is configured correctly in administration.config.
---------------------------
OK  
---------------------------

IISError

The solution was to uninstall and reinstall IIS7 from Vista. 

1) Go to Control Panel
2) Programs and Features
3) Turn Windows features on or off
4) Uncheck Internet Information Services
5) OK
6) PC will need to reboot
7) Check Internet Information Services (enable all the options you care to)
8) Volia!

Hope this helps someone out there.

Saturday, March 15, 2008

Shadowing Data Changes In MySql

I was inspired by the very capable DBA, blindman to create a utility that will allow you to shadow data changes in a MySql database. The inspiration came after viewing and using a script created by him to shadow (or archive) data in a MS Sql Server database.

What do I mean by "Shadowing"?
This will probably help a little:
Capture

Capture2
The shadow table is a duplicate of the real table except for two exceptions:
1) Constraints (Primary Keys/Foreign Keys/Data value constraints, etc) are relaxed.
2) A bit field is added to indicate whether or not the row was deleted.

So what the script does is generates the DDL for the shadow table, as well as create scripts for all the needed triggers. These triggers copy the data column for column into the archive table anytime the record is inserted, updated, or deleted. If the record is deleted then the deleted flag is turned on. Very useful functionality if you wanted to have a very strict audit of all data changes or if you wanted to have historical "snapshots" of data.

Getting this functionality in a MySql database
The app that I came up with is very simple. All I needed was:
1) A listing of all tables.
2) A listing of the columns for the tables, as well as data types, lengths, null/not null, and the default value for each.
3) The structure of a simple INSERT/UPDATE/DELETE trigger in MySql.

For #1, MySql provides a very simple "SHOW TABLES" command:
Capture3
#2 I use the "SHOW COLUMNS FROM <XXX>"
Capture4

We're half way there. Now all I needed was to learn the syntax for INSERT/UPDATE/DELETE triggers.
It's very simple:

DROP TABLE IF EXISTS sample_arc;
CREATE TABLE `sample_arc` ( `SampleID` int(11) NOT NULL, `SampleText` varchar(100) DEFAULT 'jlkj',
`MoreSampleText` varchar(20) DEFAULT NULL, `EvenMoreSampleText` varchar(255) DEFAULT NULL,
`Flag` bit(1) DEFAULT NULL, `DeletedFlag` bit(1) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TRIGGER IF EXISTS INSERT_sample;
CREATE TRIGGER INSERT_sample AFTER INSERT ON sample FOR EACH ROW INSERT INTO sample_arc
(SampleID,SampleText,MoreSampleText,EvenMoreSampleText,Flag,DeletedFlag)
VALUES (NEW.SampleID,NEW.SampleText,NEW.MoreSampleText,NEW.EvenMoreSampleText,NEW.Flag,0);
DROP TRIGGER IF EXISTS UPDATE_sample;
CREATE TRIGGER UPDATE_sample AFTER UPDATE ON sample FOR EACH ROW INSERT INTO sample_arc
(SampleID,SampleText,MoreSampleText,EvenMoreSampleText,Flag,DeletedFlag)
VALUES (NEW.SampleID,NEW.SampleText,NEW.MoreSampleText,NEW.EvenMoreSampleText,NEW.Flag,0);
DROP TRIGGER IF EXISTS DELETE_sample;
CREATE TRIGGER DELETE_sample AFTER DELETE ON sample FOR EACH ROW INSERT INTO sample_arc
(SampleID,SampleText,MoreSampleText,EvenMoreSampleText,Flag,DeletedFlag)
VALUES (OLD.SampleID,OLD.SampleText,OLD.MoreSampleText,OLD.EvenMoreSampleText,OLD.Flag,1);

The code
I wrote a little quick and dirty application in C# app to get the job done for me. It reads the tables and columns of a given database, and outputs a script to a file that can be run in MySql to create the needed tables and triggers.

For those interested, you can download the source here:
Link

If someone wanted to they could create a provider model for the app so that you could create the same functionality for different database platforms (Sql Server/PostgresSql/Oracle,etc). A user interface could also be built as this app runs in the console.

Edit 3/29/08
After playing around with SubSonic the last few days, I think it would be great to incorporate this functionality into SubStage (A GUI for much of the SubSonic code generation functionality). The provider model is already written for the major databases, and it would be trivial to tie into. There are plenty of other utility-type code generation use cases that could be implemented into this same environment.

Thursday, March 06, 2008

Google Charts API

Wow, I just finished my first chart with the Google Charts API. I had a great use case for it and it delivered way above expectations.

I have started to work on an existing web site for "Hear The Cry" which is a ministry of Vineyard Church of Columbus. The feature request was to add a progress indicator for each project to visualize how the funding is progressing in terms of the project goal. Here is how it turned out: Link.

The API was incredibly easy to learn, thanks in part to the fact that the only interface to the API is via URL. Within 25 minutes I had something that looks like this:

Here is the URL which becomes the source in your img tag:
http://chart.apis.google.com/chart?cht=bhs&chs=200x50&chd=t:70|100&chco=F6D472,7AD3F7&chxt=x,y&chxl=1:|%%20Funded|0:|0|20|40|60|80|100&chf=bg,s,EBF8FE

And to update my funding status, I simply change &chd=t:70|100 to &chd=t:75|100. Cake!!!

Background/colors/and axis labels are all changeable via the URL. For a breakdown of each parameter and what it does you can hit the Google Charts Developer API docs.

With the understanding of the API and how it works now, I'm sure I could whip out some more complicated charts in no time - the API is very intuitive and straightforward.

Saturday, March 01, 2008

CONDG Presentation: ADO.Net Data Services

For the first time since my college days, I did a presentation for a few folks on Thursday night at the Central Ohio .Net Developers Group. The topic was ADO.Net data services. I really appreciated having the opportunity to speak to the group and I hope that I was able to bring some insight to the group on this emerging technology.

The format for the evening was "lightning talks" which meant that there were seven sessions lasting 15 short minutes each. This format really provided a way to get exposed to a lot of new technologies all within a 2 hour window. 15 minutes is just enough time to get exposed to the surface of the technology, but get a good enough feel for what is going on so you know whether or not you want to invest more time in getting more intimate with it.

Jeff Blankenburg posted to his blog each of the speakers and their subject matter, so I figured that I should probably get some info up on this blog to point folks in the right direction if they're looking to get started. Sometimes I find that there is so much out there on the internets that it's easy to get distracted by some of the noise that gets made about the tech. With this in mind, I am posting some of the most helpful links that really helped me understand the meat of the subject:

http://astoria.mslivelabs.com/
Where it all begins. Learn about pre-req's and download bits.

http://blogs.msdn.com/astoriateam/archive/2008/02/03/why-astoria.aspx
Why Astoria? Discusses what problem domain the technology is solving.

http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/01/27/ado-net-data-services-screencasts.aspx
Screencasts. I love 'em.

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/12/12/ado-net-data-services-part-1-building-a-simple-web-data-service.aspx
Step-by-step building a simple service.

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/03/10073.aspx
More intermediate or advanced discussion on ADO.Net Data Services. He goes into detail about how you would implement your own data source (as opposed to using Entity Framework or LINQ-to-SQL). I'm a big fan of this blog.

http://blogs.msdn.com/marcelolr/archive/2008/01/21/service-operations-in-ado-net-data-services.aspx
Add service methods to your web service. Great for implementing some of your own access logic.

http://lostintangent.com/category/adonet-data-services/
Very in-depth. If you find yourself geeked about ADO.Net Data Services after reading the above links, this is a great place to go to get your fill.