经典ASP global.asa SQL Server 2008连接字符串 [英] Classic ASP global.asa SQL Server 2008 connection string
问题描述
我得到了一个用经典ASP编写的Web应用程序,该应用程序可以从Windows 2003 Server(SQL Server 2000和IIS 6)移植到Windows 2008 Server(SQL Server 2008和IIS 7.5).
I have been given a web application written in Classic ASP to port from Windows 2003 Server (SQL Server 2000 and IIS 6) to Windows 2008 Server (SQL Server 2008 and IIS 7.5).
站点使用GLOBAL.ASA
文件定义全局变量,其中之一是用于连接到SQL Server的连接字符串(cnn
).
The site uses a GLOBAL.ASA
file to define global variables, one of which is the connection string (cnn
) to connect to SQL Server.
下面是GLOBAL.ASA
中的(旧)连接字符串:
Below is the (old) connection string from 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
值,如下所示:
The .ASP
pages then use the cnn
value like this:
strSQL = "Select * From tblUtilities order by companyname"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, Application("cnn"), adOpenKeyset
但是我无法获得连接字符串进行连接–我将其缩减为无法登录"错误消息(无论我尝试使用哪种登录ID).
However I could not get the connection string to connect – I whittled it down to a "Failed to Login" error message (no matter what Login ID I tried).
我按如下方式编辑了GLOBAL.ASA
文件,它可以正常工作.
I edited the GLOBAL.ASA
file as follows and it works.
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
的对象.
The main difference is that cnn
now contains the connection string, where as previously cnn
was an object referring to ADOBD.Connection
.
我的问题是,这将对应用程序产生什么影响(如果有).我已经完成了一些基本的(本地)测试,此刻一切正常.但是我想知道当再次部署该站点时是否可能会出现多用户问题(或类似性质的问题).
The question I have is what impact (if any) will this have on the application. I have done some basic (local) testing and everything looks ok at the moment. But I am wondering if there might be multi-user issues (or something of that nature) that might arise when this site is deployed again.
推荐答案
建立数据库连接字符串的最佳和最简便的方法之一是在根目录或其他位置创建一个新的ASP文件,并包含连接字符串进入它:
One of the best and easiest way to connect to create a Database Connection String is to crease a new ASP file in the root directory or elsewhere and include the Connection string into it:
//Global.asp//
//Global.asp //
<%
Dim connectionString
connectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=YourSQLServer;UID=sa;PWD=*******;DATABASE=YourDataBase"
%>
然后在要调用此连接的每个文件中创建一个include语句.
Then create an include statement in each file that you would like to call this connection.
<!-- #include virtual="global.asp" -->
然后,在需要设置连接调用的地方,只需使用代码即可连接到数据库:
Then, where you need to setup your connection call, simply use your code to connect to the Database:
<%
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open = ConnectionString
Set rsReports = Server.CreateObject("ADODB.Recordset")
strSQL = "Select * From Customers"
rsReports.Open strSQL, adoCon
%>
这篇关于经典ASP global.asa SQL Server 2008连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!