📄 readme.htm.base
字号:
<OL>
<LI>Select the SQL Server driver. </LI>
<LI>Name the data source "IMDBSample1", the same name that you specified for the <B>Provider Data Source</B> field in the IMDB data source configuration. Optionally, enter a description. </LI>
<LI>Specify the location of the SQL Server installation that this system DSN will connect to. If you installed SQL Server as part of this sample installation, and/or if SQL Server is installed on the machine you are currently working on, select <B>[local]</B>. Click <B>Next</B>. </LI>
<LI>In this sample, you will use a user-supplied database userid and password to connect IMDB and SQL Server. In other samples, you will use a more secure method using trusted connections. For now, select the <B>With SQL Server authentication</B> radio button. Specify "Sa" as the <B>Login ID</B> and leave the <B>Password</B> blank. Click <B>Next</B>. </LI></OL>
<UL>
<UL>
<LI>The ODBC configuration will now actually attempt to login to SQL Server with the user information you specified. If this is successful, the next wizard page appears. If the login attempt is not successful, your SQL Server installation is not configured properly.</LI></UL>
</UL>
<OL>
<LI>Change the default database to "pubs", and leave the checkbox checked. </LI>
<LI>Click <B>Next</B> several times, accepting all the defaults for the remaining configuration parameters. Finally, you are given the option to <B>Test Data Source</B>. Do so now. </LI></OL>
<UL>
<UL>
<LI>You should see a message that the tests were completed successfully. If you see an error, your ODBC configuration or SQL Server configuration is incorrect.</LI></UL>
</UL>
<OL>
<LI>When the <B>Test Data Source</B> test executes successfully, click <B>OK</B> to exit the ODBC Data Source Administrator. </LI></OL>
<P>You have successfully configured an ODBC System DSN that is called by the OLE DB Provider for ODBC when a client tries to open a connection to a database. With this step, all the components required to run this IMDB sample are configured correctly, and all that is required is for you to <A HREF="#IMDBSAMPp3">run the sample</A>. <A NAME="IMDBSAMP1K">
<H4>Restart the IMDB Service</H4>
<P>In order for your configuration changes to take effect, to load tables from newly defined data sources (remember that it was disabled initially) simply restart the IMDB system service. If the IMDB system service does not restart correctly, you may opt to restart the system. <A NAME="IMDBSAMPp3">
<H4>Phase 3: Sample Execution</H4>
<P><A NAME="IMDBSAMP1L">
<H4>Run the sample</H4>
<P>To execute the sample, copy the following files into the Internet Information Service's \wwwroot directory that was created during <A HREF="#IMDBSAMP1C">step 3 of the Installation Phase</A>.
<UL>
<LI>IMDBSamp1A.asp </LI>
<LI>IMDBSamp1B.asp </LI></UL>
<P>In addition, copy IMDBDemo1.gif into the Internet Information Service's \wwwroot\images directory.
<P>Open the <B>IMDBSamp1A.asp</B> file by typing a fully qualified URL in Internet Explorer (for example, http://mycomputer/IMDBSamp1A.asp). When the page loads, you can select various options to retrieve records from a table loaded in IMDB from SQL Server, and perform simple operations on the data.
<P>To initially test IMDB, and your configuration, select the MSIMDB provider, the authors table, enable the <B>Display Data</B> checkbox, and click the <B>Submit</B> button. A <B>Recordset</B> is retrieved, formatted in a table, and served back to Internet Explorer. See the <A HREF="#CodeTour">Code Tour</A> section for more detail on the options that are presented, and an explanation of the techniques that were used to create this data access active server page. <A NAME="CodeTour">
<H3>Code Tour</H3>
<P>The active server pages in this sample use VBScript and Activex Data Objects to access data in IMDB and SQL Server. ActiveX Data Objects (ADO) is a powerful set of data access components that is built on an OLE DB foundation. OLE DB, and therefore ADO, uses <I>data consumers</I> and <I>data providers</I> as a basic client-server database access architecture. A data consumer is any client that requests and manipulates data. In this sample, Internet Explorer acts as the data consumer.
<H5><B>Data Providers</B></H5>
<P>An OLE DB data provider, or simply OLE DB provider, is a component that provides data to a consumer. OLE DB does not limit the role of the OLE DB provider to traditional databases; almost anything, including e-mail, text files and so on, can provide data.
<P>In this sample we use two different OLE DB providers (one only indirectly). One you are already familiar with: the OLE DB Provider for ODBC, MSDASQL. MSDASQL is a commonly used OLE DB provider that can access any ODBC 3.0-compliant database. You configured IMDB to use MSDASQL previously in the <A HREF="#IMDBSAMPp2">Configuration Phase</A> of this sample.
<P>The other OLE DB provider used in this sample is IMDB itself. When you submit the initial form (IMDBSamp1A.asp) to Internet Information Services, you use MSIMDB and retrieve data from IMDB tables. IMDB, in turn, uses MSDASQL to initially load tables from the SQL Server that you specified in your ODBC System DSN.
<H5><B>IMDBSamp1A.asp</B></H5>
<P>The initial page you open when you start the sample is the IMDBSamp1A.asp page. In order for IMDB to work correctly, you must open this page with a fully qualified URL (for example, http://mycomputer/IMDBSamp1A.asp). The IMDBSamp1A page is a simple HTML form that submits user input to a web server. You must click the <B>Display Data</B> checkbox if you want to view the ADO <B>Recordset</B> that is returned to the client from IMDB; otherwise, the only information you will see is the amount of time it took to retrieve the <B>Recordset</B>.
<P>The most important line of HTML on this page is the following:
<! ---- Begin Code Citation. ---- >
<P><TABLE BORDER=0 WIDTH=80% ALIGN=CENTER BGCOLOR="#EEEEEE">
<TR><TD WIDTH=100% ALIGN=LEFT VALIGN=MIDDLE>
<PRE> <FONT FACE="COURIER" SIZE = "2">
<! ---- Begin cited code. ---- >
<FORM ACTION="IMDBSamp1B.asp" METHOD=POST>
<! ---- End cited code. ---- >
</FONT></PRE></TD></TR>
</TABLE>
<! ---- End Code Citation. ---- >
<P>This directs the user input from the form on this page to another active server page, IMDBSamp1B.asp. IMDBSamp1B.asp is where all the work is done to access data in IMDB through Internet Information Services.
<H5><B>IMDBSamp1B.asp</B></H5>
<P>The IMDBSamp1B active server page contains VBScript that creates ADO data access components, which in turn access a data source. The VBScript on this page is never directly viewed by the user. You can open IMDBSamp1B.asp in Notepad or Wordpad to examine the VBScript code in more detail.
<P>Roughly the first half of the IMDBSamp1B.asp code is simply declaring variables and assigning the values that the user submitted with the IMDBSamp1A form to these variables. This is no different than any other VBScript, and has nothing to do with data access.
<P>The second half of the page contains the data access code, and begins with the <PRE>'''Start of ADO code</PRE>
VBScript comment. Two very important objects, the <B>ADODB.Connection</B> and <B>ADODB.Recordset</B> are created with calls to <B>Server.CreateObject</B> and are assigned to two variables that were declared initially, cn and rs.
<P>The ADO <B>Connection</B> object has several properties that must be set before it can be opened to a data source, including the <B>Provider</B> and <B>ConnectionString</B> properties. Once these properties are set, the <B>Open</B> method is called to open a connection to a data source specified in the <B>ConnectionString</B> property:
<! ---- Begin Code Citation. ---- >
<P><TABLE BORDER=0 WIDTH=80% ALIGN=CENTER BGCOLOR="#EEEEEE">
<TR><TD WIDTH=100% ALIGN=LEFT VALIGN=MIDDLE>
<PRE> <FONT FACE="COURIER" SIZE = "2">
<! ---- Begin cited code. ---- >
cn.Provider = "MSIMDB"
cn.ConnectionString = "IMDB_DS1"
cn.CursorLocation = 1 ' adUseNone
cn.Properties("OLE DB Services") = 0
cn.Open
<! ---- End cited code. ---- >
</FONT></PRE></TD></TR>
</TABLE>
<! ---- End Code Citation. ---- >
<P>The connection string is a common concept for many data access methods, including ODBC, OLE DB, RDO, DAO and so on. ADO supports seven arguments for the <B>ConnectionString</B> property (any other arguments pass directly to the provider without any processing by ADO). However, IMDB accepts only two of these arguments: <I>Provider</I> and <I>Data Source</I>. Any other arguments that you specify for the <B>ConnectionString</B> property will return error 3251. The arguments IMDB supports are as follows:
<TABLE CELLSPACING=0 BORDER=0>
<TR><TD VALIGN="MIDDLE">
<P><B>Argument</B></TD>
<TD VALIGN="MIDDLE">
<B><P>Description</B></TD>
</TR>
<TR><TD VALIGN="MIDDLE">
<I><P>Provider</I></TD>
<TD VALIGN="MIDDLE">
<P>Specifies the name of a provider to use for the connection.</TD>
</TR>
<TR><TD VALIGN="MIDDLE">
<I><P>Data Source</I></TD>
<TD VALIGN="MIDDLE">
<P>Specifies the name of a data source for the connection, for example, a SQL Server database registered as an ODBC data source.</TD>
</TR>
</TABLE>
<P>The <I>adUseNone</I> <B>CursorLocation</B> property is set on the <B>Connection</B> object and inherited by any <B>Recordset</B> that is derived from it. The <I>adUseNone</I> property is generally undocumented for ADO, but is commonly used with IMDB. For more information, see <B>Setting the ADO Cursor Location</B> in the IMDB programmer's documentation.
<P>Finally, the <CODE>cn.Properties("OLE DB Services") = 0</CODE> line explicitly disables OLE DB Service Components. OLE DB Service Components provide pooling support, auto-enlistment in transactions, and other low-level support that is not useful when programming COM+ applications for IMDB in ADO. For more information, see <B>Disabling Service Components in ADO</B> in the IMDB programmer's documentation.
<P>The <B>Recordset</B> object has several properties that also can be set before it can be opened with the current connection, including the <B>Source</B> and <B>ActiveConnection</B> properties. Once these properties are set, the <B>Open</B> method is called to open a <B>Recordset</B> that contains data retrieved from the table specified in the <B>Source</B> property:
<! ---- Begin Code Citation. ---- >
<P><TABLE BORDER=0 WIDTH=80% ALIGN=CENTER BGCOLOR="#EEEEEE">
<TR><TD WIDTH=100% ALIGN=LEFT VALIGN=MIDDLE>
<PRE> <FONT FACE="COURIER" SIZE = "2">
<! ---- Begin cited code. ---- >
Set rs.ActiveConnection = cn
rs.Source = table_name
rs.Open , , 3, 3, 2 'adOpenDynamic, adLockOptimistic, adCmdTable
<! ---- End cited code. ---- >
</FONT></PRE></TD></TR>
</TABLE>
<! ---- End Code Citation. ---- >
<P>The <B>Open</B> method syntax is as follows:
<CODE><P>recordset.Open <I>Source, ActiveConnection, CursorType, LockType, Options</I></CODE>
<P>As you can see, you can either specify the properties of the <B>Recordset</B> separately, or on the <B>Open</B> command. We have done a little of both here, by specifying the <B>Source</B> and <B>ActiveConnection</B> separately and the other three parameters on the <B>Open</B> command. The <B>ADODB.Recordset.Open</B> method is perhaps the most important method in ADO. For more information on this method, see the Microsoft Data Access documentation.
<P>The Sort and Filter options are managed next, by two simple <CODE>IF THEN</CODE> statements. These operations are
accomplished by setting the appropriate <B>Sort</B> or <B>Filter</B> properties on the <B>Recordset</B> object.
<! ---- Begin Code Citation. ---- >
<P><TABLE BORDER=0 WIDTH=80% ALIGN=CENTER BGCOLOR="#EEEEEE">
<TR><TD WIDTH=100% ALIGN=LEFT VALIGN=MIDDLE>
<PRE> <FONT FACE="COURIER" SIZE = "2">
<! ---- Begin cited code. ---- >
IF sort_records THEN
rs.Sort = rs.Fields(sort_field).Name & " " & sort_order
END IF
IF filter_records THEN
rs.Filter = rs.Fields(filter_field).Name & " = '" & filter_value1 & "' _
AND " & rs.Fields(filter_field).Name & " <= '" & filter_value2 & "'"
END IF
<! ---- End cited code. ---- >
</FONT></PRE></TD></TR>
</TABLE>
<! ---- End Code Citation. ---- >
<P>Finally, the <B>Recordset</B> is displayed to the user in tabular form, using a simple VBScript <CODE>FOR</CODE> loop.
<H5><B>Summary</B></H5>
<P>Using only a few instructions in VBScript and ADO, the sample successfully connects to and retrieves a <B>Recordset</B> from IMDB. In this sample we performed some basic operations, including opening a connection to a data source, retrieving a set of data, and sorting and filtering that data.
<P> </p>
<HR>
<P> </P>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -