国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

一種比使用include adovbs.inc更好的方法

2024-07-21 02:15:38
字體:
供稿:網(wǎng)友
注冊會員,創(chuàng)建你的web開發(fā)資料庫,using metadata to import dll constants
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 "metadata 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!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 昭觉县| 龙州县| 东阳市| 昆山市| 耿马| 绥棱县| 菏泽市| 离岛区| 类乌齐县| 固阳县| 汉川市| 江油市| 永宁县| 手游| 婺源县| 藁城市| 清镇市| 石阡县| 彝良县| 平山县| 恩施市| 宝清县| 屏山县| 秦安县| 贵港市| 丹江口市| 中方县| 那坡县| 仙桃市| 宜章县| 霍邱县| 普定县| 壤塘县| 吕梁市| 前郭尔| 商洛市| 安陆市| 南郑县| 卢氏县| 景东| 揭西县|