经典ASP global.asa SQL Server 2008连接字符串

时间:2015-06-16 12:21:34

标签: sql-server-2008 asp-classic global.asa

我获得了一个用Classic ASP编写的Web应用程序,用于从Windows 2003 Server(SQL Server 2000和IIS 6)移植到Windows 2008 Server(SQL Server 2008和IIS 7.5)。

该站点使用GLOBAL.ASA文件来定义全局变量,其中一个是连接到SQL Server的连接字符串(cnn)。

以下是来自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的对象。

我遇到的问题是这会对应用程序产生什么影响(如果有的话)。我做了一些基本的(本地)测试,目前一切看起来还不错。但我想知道在再次部署此站点时是否会出现多用户问题(或某种性质问题)。

2 个答案:

答案 0 :(得分:0)

我将连接字符串保留在Global.asa中,但在根据需要加载的单独函数中创建连接。应用程序连接对象可能不知道可能关闭该连接的临时网络问题,然后将来尝试使用该连接将不会成功。

希望这是有道理的。

答案 1 :(得分:0)

连接以创建数据库连接字符串的最佳和最简单的方法之一是在根目录或其他地方创建新的ASP文件,并在其中包含连接字符串:

// Global.asp //

def consolidate_data_files (file_names, thread_count):
output_file_names = [] 
joined_frame = None
file_count = 0
for file in file_names:
    data_frame = pandas.read_csv(str(file), quoting=csv.QUOTE_NONE, dtype=str)
    if file_count == 0:
        joined_frame = data_frame
    else:
        joined_frame = data_frame.merge(joined_frame, how='outer')
    file_count += 1
total_row_count = len(joined_frame.index) 
row_per_file = math.ceil(total_row_count/thread_count)
merged_file_count = int(math.ceil(total_row_count/row_per_file); 
for i in range(merged_file_count):
    file = "merged_file_"+str(i)+".csv"
    output_file_names.append(file)
    row_start = int(i * row_per_file)
    row_end = int(row_start + row_per_file)
    joined_frame[row_start:row_end].to_csv(path_or_buf=file, index=False, quoting=csv.QUOTE_NONE)
del joined_frame
return output_file_names 

然后在每个要调用此连接的文件中创建一个include语句。

<%
Dim connectionString
connectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=YourSQLServer;UID=sa;PWD=*******;DATABASE=YourDataBase"
%>

然后,在需要设置连接调用的地方,只需使用代码连接到数据库:

<!-- #include virtual="global.asp" -->