A better way than using include Adovbs.inc

Source: Internet
Author: User
Tags constant dsn uuid
Ado|include Using METADATA to Import DLL Constants
One disadvantage of ASP is component, the component ' s constants aren ' t immediately avaialable. For example, if your want to use the ADO constant adOpenStatic your need to include adovbs.inc. While there are nothing wrong with this, wouldn ' t it being nice don't to have to always do sure to include adovbs.inc all time That's 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 so 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 the <!--#include virtual= "/adovbs.inc"; The METADATA tag has the following form:

<!--METADATA
Type= "TypeLib"
File= "FileName"
Uuid= "Tylelibraryuuid"
-->



The 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, or through the UUID. For example, in my machine, the following two statements would is 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 the "place" METADATA tag in place of the #include. For example, the ' the ' examined would is 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.i NC "? So, no one probably would want to did that. However, you can place the METADATA tag in your Global.asa file, which'll give every ASP page in your Web application kn Owledge 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 don't do so, just to make me happy?)

Anyway, besides saving typing and has to include adovbs.inc in all of your pages this need to access ADO constants, USI Ng METADATA supposedly increases performance. At least according to Microsoft. All I could find regarding the performance boost is one sentence-no benchmarks, no hard numbers. The sole sentence reads as follows:

The 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 and include adovbs.inc when using the METADATA tag in GLOBAL.A SA, you'll get a Name redefined error. Second, the METADATA tag would only work with IIS 4.0 and up.

Comments from Alert Reader Rohan P.
I was just looking in the article Using "METADATA to Import DLL Constants". There are a couple of points worth bearing in mind.
Firstly, can import any type Libray constants to 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 the GUID of the type know, or referencing the DLL directly. Just go to Projects-references. All of the type libraries are listed there, and when selected, 'll automatically get written into Global asa!

So, there you have it. Happy programming!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.