Last week I published an oddly popular post about version controlling access databases. Could be that other people are also responsible for maintaining an access database? Letâ€™s pause for a moment and sigh collectively.
If you read this blog with any frequency(hi, mom!) then youâ€™ll know that Iâ€™m big on producing automatic builds. Iâ€™m not the only one, it is even part of the Joel test. How can we get access to build from the source files automatically? Â Unsurprisingly it turns out it sucks.
Because the source files are separated from the compiled database something needs to assemble the files into the accdb file. In an ideal world the assembly would be done by a command line build tool. Â No such tool exists. I tried to create one but I ended up deep in a COM hole attempting to call the source control bindings in Access without having to open up the UI. Turns out that this COM stuff, which largelyÂ disappearedÂ before I started programming on Windows, is kind of hard. I backed away from thatÂ approachÂ and instead I made use of a UI automation library called White.
White is an open source project which I believe came out of Thoughworks back in the day. Since then it has been picked up a group of people known as TestStack. Â There was a flurry of activity when they first started maintaining the tool but thatâ€™s died of since. Iâ€™ll do a more in detailed post on White and how to use it at a later date.
Unfortunately, I canâ€™t release everything I did to get Access to build the sourceÂ controlledÂ version of my database as myÂ employerÂ isnâ€™t big on releasing things through open source. I think I can get away with some general hints, though.
The first thing is to launch Access without any flags which, once youâ€™ve included White.Core looks like
var application = Application.Launch(@"c:Program Files (x86)Microsoft OfficeOffice14MSACCESS.EXE");
Then you basically just drive the UI as if it were you at the keyboard. Selecting a ribbon tab requires using the Window.Tabs collection and firing a Click event on the appropriate tab, in this case Source Control. Then it is just a question of selecting Create from Team Foundation and driving the rest of the UI.
With this approach I could easily generate the required accdb file. I havenâ€™t got there yet but Iâ€™m going to tie the building application into TFS as a build step so that full packages can be generated.