【发布时间】:2015-09-01 06:21:04
【问题描述】:
我收到了一个用 Classic ASP 编写的 Web 应用程序,用于从 Windows 2003 Server(SQL Server 2000 和 IIS 6)移植到 Windows 2008 Server(SQL Server 2008 和 IIS 7.5)。
该站点使用GLOBAL.ASA 文件来定义全局变量,其中之一是连接字符串 (cnn) 以连接到 SQL Server。
以下是来自GLOBAL.ASA 的(旧)连接字符串:
Sub Application_OnStart
Dim cnnDem, cnnString
Set cnnDem = Server.CreateObject("ADODB.Connection")
cnnDem.CommandTimeout = 60
cnnDem.Mode = admodeshareexclusive
cnnString = "Provider=SQLOLEDB; Data Source=192.xxx.x.xx; User Id=xxxx; Password=xxxxx; default catalog=xxxxxxx;"
Application("conString")=cnnString
Call cnnDem.Open(cnnString)
Application("cnn") = cnnDem
End Sub
.ASP 页面然后使用 cnn 值,如下所示:
strSQL = "Select * From tblUtilities order by companyname"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, Application("cnn"), adOpenKeyset
但是我无法获取连接字符串以进行连接 - 我将其缩减为“无法登录”错误消息(无论我尝试使用什么登录 ID)。
我按如下方式编辑了GLOBAL.ASA 文件,它可以工作。
Sub Application_OnStart
Dim cnnDem, cnnString
Set cnnDem = Server.CreateObject("ADODB.Connection")
cnnDem.CommandTimeout = 60
cnnString = "Provider=SQLNCLI10.1;User Id=xxxx; Password=xxxxx;Initial Catalog=xxxxxxx;Data Source=xxxxxx\SQLEXPRESS;"
Application("conString")=cnnString
Application("cnn")=cnnString
Call cnnDem.Open(cnnString)
End Sub
主要区别在于cnn 现在包含连接字符串,而之前的cnn 是一个引用ADOBD.Connection 的对象。
我的问题是这会对应用程序产生什么影响(如果有的话)。我已经进行了一些基本(本地)测试,目前一切正常。但我想知道再次部署此站点时是否可能会出现多用户问题(或类似性质的问题)。
【问题讨论】:
-
来自 MSDN - don't cache a connection in
Application (or Session)- 考虑到连接池,无论如何都不会有什么好处。您可以将连接字符串本身存储在应用程序状态中。 -
谢谢你,斯图尔特
标签: sql-server-2008 asp-classic global.asa