正确关闭数据库连接-VBScript + MS SQL [英] Properly closing a database connection - VBScript + MS SQL

查看:81
本文介绍了正确关闭数据库连接-VBScript + MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到SQL Server的经典ASP(vbscript)Web应用程序.在某些页面上,我打开了多个数据库连接以提取数据.

I have a classic ASP (vbscript) web app that connect to an SQL server. On certain pages, I open multiple DB connections to pull data.

我的问题是:

在每个页面的底部添加关闭连接功能还是在使用后立即显式关闭连接更好?请记住,在这些特定页面上,每次获取数据时我都会重新打开数据库连接.我不重用连接. IE浏览器:

Is it better to add a close connection function at the bottom of each page or to explicitly close the connection right after using it? Keep in mind, on these certain pages, I reopen a DB connection everytime I get data; I do not reuse the connection. IE:

Set DBread = Server.CreateObject("ADODB.Connection")
DBread.Mode = adModeRead
DBread.Open (SQL_DB_CONN)

当我关闭连接时,我使用:

When I close the connection, I use:

DBread.Close
Set DBread = Nothing

因此,我应该不断打开然后关闭连接还是不断打开连接,然后在页面末尾将它们关闭一次?

So, should I constantly open then close the connection OR constantly open connections, then close them once at the end of a page?

推荐答案

您应该打开一个连接并在页面顶部进行所有查询,然后在执行完最后一个查询后立即关闭连接

You should open one connection and make all queries at the top of your page then close the connection as soon as the last query has executed

示例:

Set DBread = Server.CreateObject("ADODB.Connection")
DBread.Mode = adModeRead
DBread.Open (SQL_DB_CONN)

'Make SQL Calls Here and Save rows of data by using the getrows function

DBread.Close
Set DBread = Nothing

'Process rows of data here

这篇关于正确关闭数据库连接-VBScript + MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆