one disadvantage of asp is that when using a component, the component's constants aren't immediately avaialable. for example, if you want to use the ado constant adopenstatic you need to include adovbs.inc. while there is nothing wrong with this, wouldn't it be nice not to have to always be sure to include adovbs.inc each time that you wanted to use an ado constant?
your days of including adovbs.inc are over! the metadata tag can be used to automatically import the constants from a dll or tbl file. for example, imagine that we wanted to crate a recordset object with a keyset cursor. we'd have to use code similar to:
<!--#include virtual="/adovbs.inc"-->
<%
dim objconn, strsql
set objconn = server.createobject("adodb.connection")
objconn.open "dsn=blah"
strsql = "select * from table1"
dim objrs
set objrs = server.createobject("adodb.recordset")
objrs.open strsql, objconn, adopenkeyset
'...
%>
we can use the metadata tag in place of the <!--#include virtual="/adovbs.inc"-->. the metadata tag has the following form:
<!--metadata
type="typelib"
file="filename"
uuid="tylelibraryuuid"
-->
first off, you need to set type="typelib". concerning the other two parameters, file and uuid, you need to only specify one. you can either specify the tbl or dll file directly with the file property, or through the uuid. for example, on my machine, the following two statements would be identical:
<!-- metadata
type="typelib"
uuid="00000200-0000-0010-8000-00aa006d2ea4"
-->
and
<!-- metadata
type="typelib"
file="c:/program files/common files/system/ado/msado20.tlb"
-->
you can then place this metadata tag in place of the #include. for example, the first script we examined would be changed to:
<!-- metadata
type="typelib"
file="c:/program files/common files/system/ado/msado20.tlb"
-->
<%
dim objconn, strsql
set objconn = server.createobject("adodb.connection")
objconn.open "dsn=blah"
strsql = "select * from table1"
dim objrs
set objrs = server.createobject("adodb.recordset")
objrs.open strsql, objconn, adopenkeyset
'...
%>
now, why would anyone want to use this longer metadata tag on each page as opposed to the standard #include file="adovbs.inc"? well, no one probably would want to do that. however, you can place the metadata tag in your global.asa file, which will give every asp page in your web application knowledge of the ado constants! pretty sweet, eh? the metadata tag should come before the <script ...> block in global.asa. (it doesn't have to be placed there, but why not do that, just to make me happy?)
anyway, besides saving typing and having to include adovbs.inc in all of your pages that need to access ado constants, using metadata supposedly increases performance. at least according to microsoft. all i could find regarding the performance boost was one sentence- no benchmarks, no hard numbers. the sole sentence reads as follows:
"avoid using server-side #include directives to include large lists of constants. use the new <metadata> tag to import type-library constants into global.asa"
-- taken from asp performance tips
a couple of caveats: first, from alert reader daniel s., if you include adovbs.inc when using the metadata tag in global.asa, you will get a name redefined error. second, the metadata tag will only work with iis 4.0 and up.
comments from alert reader rohan p.
i was just looking at the article using "met
|||adata to import dll constants". there are a couple of points worth bearing in mind.
firstly, you can import any type libray constants into global asa, not just the ado ones. i also import the filesystemobject and cdo constants this way.
secondly, visual interedev 6 gives you a neat way of doing it without needing to either know the guid of the type libray, or referencing the dll directly. just go to projects - references. all the type libraries are listed there, and when selected, will automatically get written into global asa!
well, there you have it. happy programming!