A few years back, articles like this one from 4 guys started deprecating the use of # include statements for adovbs. INC and adojavas. inc as the way to in1_ate common constants into your projects. the new suggestion was to use a <metadata> statement -- either within the current page, or inside the application'sGlobal. asa-- To add a reference to the desired constants.
Ornery as usual, I resisted the suggestion. today's article discusses some issues and limitations in the use of metadata typelib tags, and suggests a few workarounds for diehards who just can't live without them.
First, the conventional wisdom
Here's how it's supposed to work. The <metadata> tag is an HTML comment line with the following general syntax:
<! -- Metadata type = "typelib" file = "Explicit operating-system filespec" UUID = "{typelibraryuuid}" version = "majorversionnumber. minorversionnumber" lcid = "localeid" -->
Although the official syntax doesn't support it, for documentation about people -- including some of Microsoft's example code -- add an additional parameter to the tag, the "name" parm. it turns out that this parm is ignored by everyone, but it's sometimes useful as instream self-documentation.
<! -- Metadata type = "typelib" name = "Some descriptive string" file = "Explicit operating-system filespec" UUID = "{typelibraryuuid}" version = "majorversionnumber. minorversionnumber "lcid =" localeid "-->
When specifying a typelib, you wowould typically provide either a "file" parameter or a uuid parameter, but not both. Here's an example that specifies the file parameter:
<! -- Metadatatype = "typelib" file = "C: \ Program Files \ common files \ System \ ADO \ msado15.dll" -->
And here's an example that specifies the uuid parameter:
<! -- Metadatatype = "typelib" UUID = "{00000205-0000-0010-8000-00aa006d2ea4}" -->
There's one other thing to bear in mind throughout this discussion. just like # include directives, metadata tags are interpreted during the ASP pre-compile step. that is, their internal references are resolved before any ASP code is parsed. this means that you cannot perform any conditional logic at run time, to figure out -- for example -- where some file might exist. one other upshot of this pre-compile issue is that it is not possible to gracefully recover from an invalid typelib specification.
... And problems with conventional wisdom
Diligent readers will have spotted the first two problems.
- To use the file method, you need to know the explicit location of the DLL or TLB, and specify it inside your website at development time. if the file moves elsewhere, you have to modify your source code.
- To use the uuid method, you need to know the uuid of the DLL, and specify it inside your website at development time. if a new version uses a different UUID, You have to modify your source code.
the good news -- when we're re looking at ADO anyway -- is that Microsoft used to enforce some uniformity on the installation process. in general, MDAC INSTALLThe ADO libraries inside the directory "Program Files \ common files \ System \ ADO \", located on the system boot drive. the bad news -- for some of us -- is that we don't necessarily know what drive that is. for example, I have two development servers, and each of them boots from a different drive -- one on "D:" and one on "E :". my code is tested on my partners 'servers -- and again, there's no uniformity of boot drives. and finally I distribute and deploy my applications onto my clients 'servers, limits of which are in shared host environments where I haven' t got a clue what the boot drive is -- and in any case it cocould change at any time, at the whim of a SysAdmin.
You might think the answer is some fascist dictate to force everyone to install the operating system and the MDAC libraries on "C: \", but in the real world, that's just not practical. operating systems get installed as dual-boot deployments, hardware vendors preformat machines with miniscule "C: \" partitions, ISPs move virtual hosts around und, seemingly at random... there's lots of reasons you can't rely on finding everything on the C: Drive.
Themes and variations
So let's look at our alternatives. instead of using the "file" format of the metadata tag, we can use the "UUID" format. the following table lists the uuids for several major versions of Microsoft's MDAC technologies:
ADO |
2.0 |
{00000200-0000-0010-8000-00aa006d2ea4} |
No longer available |
2.1 |
{00000201-0000-0010-8000-00aa006d2ea4} |
Earliest version still around |
2.5 |
{00000205-0000-0010-8000-00aa006d2ea4} |
Came with a Windows 2000 |
2.6 |
{00000206-0000-0010-8000-00aa006d2ea4} |
Came with SQL Server 2000 |
2.7 |
{EF53050B-882E-4776-B643-EDA472E8E3F2} |
Came with Windows XP |
Ador |
All |
{00000300-0000-0010-8000-00aa006d2ea4} |
|
ADOX |
All |
{00000600-0000-0010-8000-00aa006d2ea4} |
|
You can download current versions of MDAC -- from 2.1 through 2.7 -- from Microsoft's download center at http://www.microsoft.com/data/download.htm.
Each of the different ADO libraries has its own series of UUID keys, as defined in the Windows registry. the primary libary -- just plain ADO -- contains the definitions for most of the major objects, and each version of the ADO library has its own top-level entry in the Series "{0000020x-0000-0010-8000-00aa006d2ea4 }" , Snapshot t -- for some bizarre reason -- the new version 2.7 library, which breaks the pattern with UUID "{EF53050B-882E-4776-B643-EDA472E8E3F2 }" .
The ADO recordset Library (Ador) is billed as a "lightweight subset" of the ADODB Type Library, and supports only recordsets. It has a single entry as defined in the Windows registry, with UUID "{00000300-0000-0010-8000-00aa006d2ea4 }" .
Ado typelib registry keys on My XP-Pro development Desktop |
|
ADOXIs the "ADO extensions for Data Definition Language and security ". ADOX is an extension to the ADO objects and programming model that provides provider-independent objects and methods that support schema and Object Security definitions for all oledb providers regardless of their native syntaxes. this object is represented by "{00000600-0000-0010-8000-00aa006d2ea4 }" UUID key.
The figure to the right shows the ADO-related typelib settings in the Registry on my XP-Pro development desktop. the machine has been around for quite a while -- it started out in life as Windows NT4, and has seen extends versions of ADO come and go. as the figure between strates, available versions of MDAC range from 1.0 (!!) To the version 2.6 and 2.7 libraries.
There are a few interesting things demonstrated by this listing:
- although the documentation says that MDAC 2.7 is distributed with Windows XP, this winxp pc doesn't seem to have an explicit {comment} entry for ADO 2.7, the way we might have expected. on the other hand, it does have an entry for MDAC 2.7 elsewhere in the Registry, under the uuid {EF53050B-882E-4776-B643-EDA472E8E3F2 }.
ADO typelib registry keys on NT 4 server with sqlserver 7.0 |
|
- On the Other Other hand, it does have entries for version 2.7 of the ADO recordset and ADO extensions libraries. this seems kinda weird, But par for the course on a typical development desktop.
The next figure to the right is a snapshot of the relevant registry keys on one of my test servers, which runs NT4 server and SQL Server 7.0. the interesting thing to notice about this snapshot is that its highest version entry is MDAC 2.5. this seems to jibe with the fact that the server runs SQL Server 7 -- and the fact that I never bothered to install a newer version of MDAC.
If you ran an ASP program on this server that contained a uuid-style reference to the ADO 2.6 typelib, it wocould throw an error that looks something like this...
Active Server Pages error 'asp 0223'
Typelib not found
/Foo. asp and line 123
Metadata tag contains a Type Library Specification that does not match any registry entry.
Ado typelib registry keys on NT 4 server with sqlserver 7.0 After installing MDAC 2.6 SP1 |
|
For grins -- and to see if I cocould make this error go away -- I downloaded and installed MDAC version 2.6 SP1 from Microsoft's download site onto the NT4 server. after the server was restarted, I rechecked the registry keys, and sure enough (see the listing to the right) the new version 2.6 entries cocould be found, and the error went away.
The Microsoft Web site contains some rather frightening language about the compatibility of SQL Server 7.0 and MDAC 2.7.
Due to issues with clustering, this release is currently not supported on SQL Server 7.0 servers or SQL 6.5 clustered servers.
Even though I suspect the warning is actually a stupid typographical error -- I think they intended to refer only to "SQL Server 7.0ClusteredServers "-- it was enough to keep me from upgrading that server any further. I decided to leave well enough alone in the NT 4 world for now, and move on to the braver, newer world of my Windows 2000 Server.
My Windows 2000 development and production servers are fairly new, and when I originally configured them, they had both Windows 2000 Server and SQL Server 2000 installed.
Ado typelib registry keys on W2k server with sqlserver 2000 |
|
So, as the figure to the right shows, these servers have the newer 2.5 and 2.6 versions of the libraries available... although not version 2.7, the "XP" release. in fact, this server even supports backward compatibility with prior versions (2.0, 2.1 and 2.5) of the ADO libraries.
What a freakin 'can of worms!
One other bizarre anomaly introduced into this process is the fact that Visual InterDev offers the ability to automatically insert metadata tags into your projects. from the main menu, select "project"; from the pulldown select "project references... "from the resulting dialog scroll to the desired library. if you selected the "ADO 2.7 library", an entry like this might be added to the "Global. asa "file in your project directory:
<! -- = Visual InterDev generated-startspan = --> <! -- Metadata type = "typelib" name = "Microsoft ActiveX Data Objects 2.7 library" UUID = "{EF53050B-882E-4776-B643-EDA472E8E3F2}" version = "2.7" --> <! -- = Visual InterDev generated-endspan = -->
However, remember that the list of available object references was generated from the list of objects installed on your desktop. as soon as you try to run the application on your server, you'll get the ill-fated "ASP 0223" error message mentioned earlier, metadata tag contains a Type Library Specification that does not match any registry entry.
One possible workaround that lets you avoid some of these version-specific hassles wocould be to use the uuid of the "ADO recordset" object instead of the ADO library itself. as you remember, it's just a "lightweight subset" of the complete ADO library, but if all you need is constants, they're all there... it wowould probably be a good idea to use the Ador library like this:
<! -- Metadata type = "typelib" UUID = "{00000300-0000-0010-8000-00aa006d2ea4}" -->
Are weThereYet?
If by this time you're still convinced you want to use metadata tags instead of # include files, here's a few things to think about:
- You might want to use the "UUID" format to avoid crashes when you run into servers where the OS wasn't installed on drive c :\.
- You have to keep track of what versions of MDAC are installed on your development when tops and servers, the maximum tops and servers of your fellow developers, and all of the servers you might want to deploy on. choose the least common denominator that supports your project requirements.
- Finally, you might consider adding a metadata reference to Ador instead of ADO. If all you need is the standard set of constants, it's probably just as good.
Any last words?
Pardon me for expressing an opinion here, but don't you get annoyed at how MS messes stuff like this up? I mean, really... couldn't this have been designed better? For example -- the reason why they designed the registry was so that the operating system cocould find files without your programs needing to specify explicit file locations... and the reason the Registry provided des monickers (aka "friendly names") is so that you don't need to know complex multi-digit uuids.
How hard wocould it have been to allow specification of a registered library using its friendly name? For example
<! -- Metadata type = "typelib" foo = "ADODB" -->
Wocould that have been so hard?
Stupid metadata tricks...
Oh, meanwhile, as long as we're in the neighborhood, I thought I 'd mention this really cute little anomaly I ran into. try this at home...
- Add a javascript section to your web page.
- Do that cute little "hide from back-level browsers" trick where you enclose your JavaScript text inside HTML comment tags.
- Add the word "metadata" anywhere inside the script.
Here's an example:
<Script language = "JavaScript"> <! -- Var Foo = "I love metadata! "; // --> </SCRIPT> <script language =" JavaScript "> <! -- Alert (FOO); // --> </SCRIPT>
Know what happens when you execute that snip of script? See the screenshot to the right for a hint.
Know why? Because as soon as IIS sees the word "metadata" anywhere inside an HTML comment, it suppresses the whole comment. And in this case, that means it suppresses the whole content of the JavaScript.
Cool, eh?