概要
本文介绍一种当使用 Microsoft VBScript 和 Microsoft JScript 编程时,在 Active Server Page (ASP) 中创建 ActiveX 数据对象 (ADO) 非连接记录集的方法。本文假定读者熟悉 ADO 和 ASP。
更多信息
ASP 的原则之一是尽快释放 ADO 对象,从而释放这些对象所使用的系统资源。ADO 非连接记录集这一功能允许记录集在没有活动连接时也能存在;这可以节省数据库服务器资源并提高伸缩性。ADO 非连接记录集要求使用客户端游标,这可以通过将Connection 对象的 CursorLocation 属性设置为adUseClient 来实现。下面的示例代码使用 Microsoft OLEDB Provider for SQL Server (SQLOLEDB) 连接到随 SQL Server 安装一起提供的 Northwind 示例数据库。要运行这些示例,需修改连接字符串和 SELECT 语句以适应您的环境。另外,还要为 ADO 常量的 Include 文件设置正确的路径。
VBScript 中的非连接记录集
- <%@Language="VBScript"%>
- <!-- Include file for VBScript ADO Constants -->
- <!--#include File="adovbs.inc"-->
- <%
- ' Connection string.
- strCon = "Provider=sqloledb;Data Source=myServer;Initial Catalog=Northwind;User Id=myUser;Password=myPassword"
- ' Create the required ADO objects.
- Set conn = Server.CreateObject("ADODB.Connection")
- Set rs = Server.CreateObject("ADODB.recordset")
- ' Open the connection.
- conn.Open strCon
- ' Retrieve some records.
- strSQL = "Select * from Shippers"
- rs.CursorLocation = adUseClient
- rs.Open strSQL, conn, adOpenStatic, adLockOptimistic
- ' Disconnect the recordset.
- Set rs.ActiveConnection = Nothing
- ' Release the connection.
- conn.Close
- ' Check the status of the connection.
- Response.Write("<BR> Connection.State = " & conn.State)
- Set conn = Nothing
- ' Use the diconnected recordset here.
- ' Release the recordset.
- rs.Close
- Set rs = Nothing
- %>
注意,记录集是通过将ActiveConnection 属性设置为 Nothing 断开连接的。
JScript 中的非连接记录集
- <%@Language="JScript"%>
- <!-- Include file for JScript ADO Constants -->
- <!--#include File="adojavas.inc"-->
- <%
- // Connection string.
- var strCon = "Provider=sqloledb;Data Source=myServer;Initial Catalog=Northwind;User Id=myUser;Password=myPassword";
- // Create the required ADO objects.
- conn = Server.CreateObject("ADODB.Connection");
- rs = Server.CreateObject("ADODB.recordset");
- // Open the connection.
- conn.Open(strCon);
- // Retrieve some records.
- var strSQL = "Select * from Shippers";
- rs.CursorLocation = adUseClient;
- rs.Open(strSQL, conn, adOpenStatic, adLockOptimistic);
- // Disconnect the recordset.
- DisconnectRecordset(rs);
- // Release the connection.
- conn.Close();
- // Check the status of the connection.
- Response.Write("<BR> Connection.State = " + conn.State);
- conn = null;
- // Use the diconnected recordset here.
- // Release the recordset.
- rs.Close();
- rs = null;
- %>
- <SCRIPT LANGUAGE="VBScript" RUNAT="SERVER">
- Sub DisconnectRecordset(rs)
- Set rs.ActiveConnection = Nothing
- End Sub
- </SCRIPT>
备注:在前面的代码中,不能将以下代码行
- DisconnectRecordset(rs);
替换为以下某个代码行来创建断开连接的记录集:
- rs.ActiveConnection = null;
- 或 -
- delete(rs.ActiveConnection);
有另外一种方法可以创建非连接记录集。JScript 中没有与 VBScript 中的Nothing 关键字(用来释放 ActiveX 对象)类似的关键字。要实现这一点,可以使用与下面的 Web 站点中提供的方法类似的方法:
http://www.netspace.net.au/~torrboy/code/jargutil
在本例中,示例代码可能类似于下面这样:
- var oUtil = Server.CreateObject("Torrboy.JArgUtility");
- rs.ActiveConnection = oUtil.Nothing;
参考
有关其他信息,请单击下面的文章编号,查看 Microsoft 知识库文章:
184397 HOWTO:Create ADO Disconnected Recordsets in VBA/C++/Java(HOWTO:在 VBA/C++/Java 中创建 ADO 断开连接的记录集)
190717 INFO:Disconnected Recordsets with ADO or RDS(INFO:ADO 或 RDS 的断开连接的记录集)
252482 BUG:ADO Disconnected Recordset That Uses Parameterized Query Is Not Disconnected by SQL Server(BUG:使用参数化查询的 ADO 断开连接的记录集没有被 SQL Server 断开连接)
http://support.microsoft.com/kb/289531/en-us
本日志由 flyinweb 于 2009-06-19 12:49:10 发表,目前已经被浏览 4299 次,评论 0 次;
引用通告:http://www.517sou.net/Article/36/Trackback.ashx
而且直接配置文件是效率最高的,通过其它驱动效率都相对较低,BDB
这个测试不太准确,看官方的测试结果:http://bind-dlz.sourceforg
为什么使用BDB时QPS这么低? 我在bind版本基本相似的环境中测试的
It is quite useful and interesting too.
VIRT 的上限是64G,也就是36位, cat /proc/cpuinfo的结果是:addre
昨天要准备用线程重写webbench,试验了下Fedora Linux 2.6.35.14
不明白您的具体的意思是什么?
已经发送到你QQ邮箱