我已经给出了一个用传统ASP编写的Web应用程序,用于从Windows 2003 Server(SQL Server 2000和IIS 6)移植到Windows 2008 Server(SQL Server 2008和IIS 7.5) 。经典ASP global.asa SQL Server 2008连接字符串
该站点使用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 - [不缓存在'应用程序的连接(或会话)'](https://msdn.microsoft.com/en-us/library/bb727078.aspx#EXAA) - 无论如何,在连接池的情况下,几乎没有任何好处。您可以将连接字符串本身存储在应用程序状态中。 – StuartLC
谢谢你,斯图尔特 –