📄 断开的数据库连接的一个例子.htm
字号:
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD bgColor=#297dff colSpan=2 height=20><FONT color=#ceffff> →
<A href="http://www.aspsky.net/article/index.asp?classid=2"><FONT
color=#ceffff>ASP技术</FONT></A> >> <A
href="http://www.aspsky.net/article/index.asp?classid=2&Nclassid=10"><FONT
color=#ceffff>数据库相关</FONT></A> >> 《断开的数据库连接的一个例子》</FONT></TD></TR>
<TR>
<TD bgColor=#586011 colSpan=2 height=1><SPACER type="block"
width="1"></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR>
<TR>
<TD align=middle class=p4
colSpan=2><B>断开的数据库连接的一个例子</B></FONT><BR>2001-12-28 动网先锋
</TD></TR>
<TR>
<TD class=p4 colSpan=2>
<BLOCKQUOTE><BR>使用断开的Recordset的一个关键条件就是使用客户端临时表,即
<P></P>
<P>指定Rs.CursorLocation = adUseClient or 3,下面是一个完整 <BR>的例子:
<BR>demo-1.asp (在线演示:http://www.aspcn.com/demo/demo-1.asp)
<BR>------------------------------------------------------------
<BR><%@ Language=VBScript %> <BR><% <BR>'#
-------------------------------------------------------------------
<BR>--------- <BR>'# 程序描述:演示使用断开的记录集 <BR>'# 程序设计:亚豪 <BR>'#
-------------------------------------------------------------------
<BR>--------- </P>
<P>On Error Resume Next <BR>Dim adoConn,adoRs,SQLCmd,ConnectString
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 使用SQL Server的 DSN-less 方式连接数据库
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>ConnectString = "Driver={SQL Server};" & _
<BR>"Server=(local);" & _ <BR>"Database=abc;" & _
<BR>"Uid=sa;" & _ <BR>"Pwd=123" </P>
<P>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 创建对象实例,并初始化连接(Connection)
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>Set adoConn =
Server.CreateObject("ADODB.Connection") <BR>Set adoRs =
Server.CreateObject("ADODB.Recordset") <BR>adoConn.Open
ConnectString </P>
<P>SQLCmd = "Select * from bbs_user where LTrim(RTrim(id)) =
'w3org'"
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 使用客户端临时表打开并保存记录集,关键所在! <BR>'#
客户端是运行ASP程序的主机,相对于数据库服务器而言
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>adoRs.CursorLocation = 3 'Const adUseClient = 3
<BR>adoRs.Open SQLCmd,adoConn,0,2 </P>
<P>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 没有发现记录,结束程序
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>Err.Clear <BR>If adoRs.EOF And adoRs.BOF Then
<BR>adoRs.Close <BR>adoConn.Close <BR>Set adoRs = Nothing <BR>Set
adoConn = Nothing <BR>Response.Write "用户没有发现!" <BR>Response.End
<BR>End If
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 找到记录,显示原来的值后释放记录集的活动连接,之后关闭数据库连接
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>Response.Write "原来的昵称是:" &
Trim(adoRs.Fields("NickName").Value) <BR>& "<br>" &
vbCrLf <BR>Set adoRs.ActiveConnection = Nothing '释放Rs的活动连接
<BR>adoConn.Close <BR>Response.Write "连接已经关闭!<br>" &
vbCrLf
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 赋一个新的值给记录的 NickName 列,这时已经没有活动的数据库连接
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>adoRs.Fields("NickName").Value = "NewTest-"
& Second(Time())
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 再次打开数据库连接,并绑定到先前的记录集上
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>adoConn.Open ConnectString
<BR>adoRs.ActiveConnection = adoConn
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 更新记录集,并显示新的值
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>adoRs.Update <BR>Response.Write "新的昵称是:" &
Trim(adoRs.Fields("NickName").Value) & <BR>"<br>" &
vbCrLf '显示一个结果
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>'# 如果发生错误则显示错误
<BR>'#--------------------------------------------------------------------
<BR>--------- <BR>If Err.number <> 0 Then <BR>Response.Write
"发生错误:" & Err.description & "<br>" <BR>End If
<BR>adoRs.Close <BR>adoConn.Close <BR>Set adoRs = Nothing <BR>Set
adoConn = Nothing <BR>%> <BR><HTML>
<BR><HEAD><Title>演示断开的连接</title></HEAD>
<BR><BR><BR></P></BLOCKQUOTE></TD></TR>
<TR>
<TD class=p4 vAlign=top width="50%">
<BLOCKQUOTE>原作者:刘子良<BR>来 源:开发者俱乐部<BR>共有4009位读者阅读过此文<BR>【<A
href="http://bbs.aspsky.net/list.asp?boardid=1">发表评论</A>】
</BLOCKQUOTE></TD>
<TD class=p4 vAlign=top width="50%">
<P>
<LI><FONT color=#0772b1>上篇文章</FONT>:<A
href="http://www.aspsky.net/article/list.asp?id=2532">本函数计算两个时间的差[原创]</A>
<BR>
<LI><FONT color=#0772b1>下篇文章</FONT>:<A
href="http://www.aspsky.net/article/list.asp?id=2534">货币大写转换函数的更新</A>
</LI></TD></TR>
<TR>
<TD bgColor=#297dff class=p4 height=20 width="50%"><FONT
color=#ceffff> → 本周热门</FONT></TD>
<TD bgColor=#297dff class=p4 width="50%"><FONT color=#ceffff> →
相关文章</FONT></TD></TR>
<TR>
<TD bgColor=#586011 colSpan=2 height=1><SPACER type="block"
width="1"></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR>
<TR>
<TD class=p4 vAlign=top width="50%">
<LI><A href="http://www.aspsky.net/article/list.asp?id=1510"
target=_top title="SQL Server 7.0 入门(一)">SQL Server 7.0
入门(...</A>[<FONT color=red>7239</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1540"
target=_top title=PHP4实际应用经验篇(1)>PHP4实际应用经验篇(1)</A>[<FONT
color=red>7135</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1536"
target=_top
title=无组件文件上传代码实例(支持多文件上传及文件和input域混合上传)>无组件文件上传代码实例(支持多文件上...</A>[<FONT
color=red>6029</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=2557"
target=_top title=树型结构在ASP中的简单解决>树型结构在ASP中的简单解决</A>[<FONT
color=red>5757</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1545"
target=_top title=PHP4实际应用经验篇(6)>PHP4实际应用经验篇(6)</A>[<FONT
color=red>5599</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=2563"
target=_top title=一个老个写的无组件上传>一个老个写的无组件上传</A>[<FONT
color=red>5013</FONT>]<BR>
<LI><A href="http://www.aspsky.net/article/list.asp?id=1542"
target=_top title=PHP4实际应用经验篇(3)>PHP4实际应用经验篇(3)</A>[<FONT
color=red>4731</FONT>]<BR></LI></TD>
<TD class=p4 vAlign=top width="50%">
<LI><A
href="http://www.aspsky.net/article/list.asp?id=2815">.NET中各种数据库连接大全</A><BR>
<LI><A
href="http://www.aspsky.net/article/list.asp?id=2533">断开的数据库连接的一个例子</A><BR></LI></TD></TR>
<TR>
<TD colSpan=2 height=7></TD></TR></TBODY></TABLE>
<TD bgColor=#297dff width=1> </TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD bgColor=#297dff height=1><SPACER type="block"
width="1"></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle height=30></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle class=p2 width="100%">
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
<TBODY>
<TR>
<TD align=middle class=p2 width="100%">
<P align=center><A
href="http://www.aspsky.net/produce/index.asp">客户服务</A> -- <A
href="http://www.aspsky.net/aspads.asp">广告合作</A> -- <A
href="http://www.aspsky.net/about.asp">关于本站</A> -- <A
href="http://www.aspsky.net/tell.asp">联系方法</A><BR><BR>动网先锋版权所有 <FONT
face=Verdana, size=1 Arial, Helvetica, sans-serif>Copyright ©
2000-2001 <B>AspSky<FONT color=#cc0000>.Net</FONT></B>, All Rights
Reserved .</FONT>
</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -