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

ado|include

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!

时间: 2024-09-22 23:30:54

一种比使用include adovbs.inc更好的方法的相关文章

一种比使用include adovbs.inc更好的方法,请看(Using METADATA to Import DLL Constants )

ado|include 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 wi

DB2提供一种更好的方法实现乐观锁定

在 IBM i 6.1 版本,DB2 为用户提供一项新功能(ROW CHANGE列)可以为需要使用乐观锁的应用程序改进其算法.乐观锁定是一种基于网络数据库应用程序中广泛应用的技术,这些应用程序一定会读取数据但是只是有可能更新读取过的数据,但其不会维持一个与数据库的持久连接.因为应用并不维持一个持久的连接,用户不能够依靠行级锁为那些后续更新的行保持数据完整性.实现乐观锁定的一个常见方法是,把这个应用程序可能稍后要更新的那一行对应的列的所有值记录在缓存中,再将这些值在接下来的更新语句作为条件. SE

2015年这八种科技让你的生活更有乐趣

  2015年才刚刚开始,经过2014年的发展,整个数字与网络技术已经又与我们的日常生活贴近了一步.而从2015年开始,我们的数字生活将会进一步被不断发展的技术所改变.尝试在我们的数字生活中做出一些改变,会让所有的事情变得更简单一些.下面就让我们看看在刚刚到来的2015年,哪些科技的新尝试将会进一步影响我们的数字生活. 所有的数据都通过云端备份 在传统的观念里,对于数据的保存通常只有三个渠道:家中电脑里的原始数据.存储装置以及额外备份.前两种方式,通常我们都会选择家中的台式机和外接硬盘,但是第三

实现ASP.NET 2.0无刷新页面更方便的方法

"无刷新页面",只是一种不确切的效果描述(其实还有其他各种方法来实现这个效果),更确切的说法是:在页面上用JavaScript调用服务器端的一个方法,然后处理返回的数据.实现它最标准的方法当然是XMLHTTP.但是,程序员都是懒惰的家伙,每个人都希望能有更方便的方法,或者,更佳的包装.比如,Lostinet的Rane就是对XMLHTTP的一个很好的包装. 终于,在ASP.NET 2.0里面,我们可以轻松的来做到这点了.服务器端任何实现了System.Web.UI.ICallbackEv

php中json_encode UTF-8中文乱码的更好解决方法_php技巧

最近在接口代码当中用到过json_encode,在网上找到说json_encode编码设置为UTF-8中文就不会乱码,经验证这办法确实是有效果的,但是不知道为什么,代码在用过一段时间之后就不太管用了.以下是自己的解决json_encode的办法.有更好的方法请分享出来吧! 第一种: 这种简单的做一个代码转换,urlcode之后再返回所需数组 我代码这样就足够了. 代码如下 复制代码 public static function encodeOperations ($array) { foreac

分析几种关于网站安全的现象以及处理的方法

摘要: 如今绝大多数站长都在想着怎么建设外链,怎么发布网站内容,把自己网站的弄到首页或是前三位,其实在这些光鲜的背后,网站安全其实也需要站长们注意,因为一旦网站安全出了问 如今绝大多数站长都在想着怎么建设外链,怎么发布网站内容,把自己网站的弄到首页或是前三位,其实在这些光鲜的背后,网站安全其实也需要站长们注意,因为一旦网站安全出了问题,网站的排名也会受到巨大的影响.下面笔者就仔细分析几种关于网站安全的现象以及处理的方法. 第一种:网站被挂"黑链" 就算百度没有更新算法,只要是碰到网站挂

获得Win32窗口句柄的更好的方法

"VC6中使用CHtmlView在对话框控制中显示HTML文件" "如何禁用HTML页面的上下文菜单" "Convert CHtmlView to CHtmlCtrl..." 这三篇文章的原文实际上都出自 MSDN Magazine 及其前身 MSJ 的"C++ Q&A"专栏作家 Paul DiLascia 之手.此君从1995年开始就成为 MS 在 C++/MFC 方面的高级写手,Paul 在 Windows 应用开

ps几种实用设计快速提取彩色图片线稿方法

  ps几种实用设计快速提取彩色图片线稿方法!卡通动漫手绘提取线稿的时候经常会使用的方法,简单粗暴~效果好 分类: PS入门教程

新手提问大神,java源代码写好后该怎么用,打包成exe?还是有别的更好的方法

问题描述 新手提问大神,java源代码写好后该怎么用,打包成exe?还是有别的更好的方法 有开发经验的大神告诉我,java源代码写好后该怎么用,打包成exe?还是有别的更好的方法,有的提到了脚本之类的 解决方案 点进去看看,试着去用用http://jingyan.baidu.com/article/358570f6727bb7ce4724fc88.html 解决方案二: 点进去看看,试着去用用http://jingyan.baidu.com/article/358570f6727bb7ce472