帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
一种比使用include adovbs.inc更好的方法
作者: 发布时间:2005-03-12 来源:chinaasp
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 FilesCommon FilesSystemADOmsado20.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 FilesCommon FilesSystemADOmsado20.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!

  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·“无法指出的错误”——连接字符  (2005-03-12)
 ·一种效率极高的分类算法  (2005-03-12)
 ·一种理论上最快的Web数据库分页方  (2005-03-12)
 ·一种函数的计算方法并给出相应的  (2005-03-12)
 ·用ASP将JAVASCRIPT代码写入客户端  (2005-03-12)
 ·又一种在线人数统计方法(只用1个  (2005-03-12)
 ·一种在父窗口中得知window.open(  (2005-03-12)
 ·创造一种迅速而又随性的(quick a  (2005-03-12)
 ·利用实体EJB来避免性能缺陷:一种  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统