经典Asp中的数据库连接错误

时间:2014-09-25 11:24:08

标签: asp-classic

我的经典ASP网站发生以下错误:

Database Results Error

The database connection named 'Database1' is undefined.

This problem can occur if:

* the connection has been removed from the web

* the file 'global.asa' is missing or contains errors

* the root folder does not have Scripting permissions enabled

* the web is not marked as an Application Root

global.asa文件也在服务器上。我不知道问题在哪里可以帮忙吗?

基本上我是一名php开发人员,现在做一些asp工作。

此网站位于根目录下的文件夹中,例如www.example.com/v2。这是导致这个问题吗?

这是我的global.asa代码:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
    '==FrontPage Generated - startspan==
    Dim FrontPage_UrlVars(1)
    '--Project Data Connection
    Application("Database1_ConnectionString") = "DRIVER={SQL Server};SERVER=*******;DATABASE=********;UID=****;PWD=********"
    Application("Database1_ConnectionTimeout") = 60
    Application("Database1_CommandTimeout") = 30
    Application("Database1_CursorLocation") = 3
    Application("Database1_RuntimeUserName") = "*****"
    Application("Database1_RuntimePassword") = "*******"
    '--
    Application("FrontPage_UrlVars") = FrontPage_UrlVars
    '==FrontPage Generated - endspan==
End Sub
Sub Session_OnStart
    FrontPage_StartSession '==FrontPage Generated==
End Sub
Sub FrontPage_StartSession
    On Error Resume Next
    if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub
    ' discover the VRoot for the current page;
    ' walk back up VPath until we find global.asa
    Vroot = Request.ServerVariables("PATH_INFO")
    strG1 = "global.asa"
    strG2 = "Global.asa"
    iCount = 0
     do while Len(Vroot) > 1
        idx = InStrRev(Vroot, "/")
        if idx > 0 then
            Vroot = Left(Vroot,idx)
        else
            ' error; assume root web
            Vroot = "/"
        end if
        if FrontPage_FileExists(Server.MapPath(Vroot & strG1)) then exit do
        if FrontPage_FileExists(Server.MapPath(Vroot & strG2)) then exit do
        if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
        iCount = iCount + 1
        if iCount > 100 then
            ' error; assume root web
            Vroot = "/"
            exit do
        end if
    loop
    ' map all URL= attributes in _ConnectionString variables
    Application.Lock
    if Len(Application("FrontPage_VRoot")) = 0 then
        Application("FrontPage_VRoot") = Vroot
        UrlVarArray = Application("FrontPage_UrlVars")
        for i = 0 to UBound(UrlVarArray)
            if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
        next
    end if
    Application.Unlock
End Sub
Sub FrontPage_MapUrl(AppVarName)
    ' convert URL attribute in conn string to absolute file location
    strVal = Application(AppVarName)
    strKey = "URL="
    idxStart = InStr(strVal, strKey)
    If idxStart = 0 Then Exit Sub
    strBefore = Left(strVal, idxStart - 1)
    idxStart = idxStart + Len(strKey)
    idxEnd = InStr(idxStart, strVal, ";")
    If idxEnd = 0 Then
        strAfter = ""
        strURL = Mid(strVal, idxStart)
    Else
        strAfter = ";" & Mid(strVal, idxEnd + 1)
        strURL = Mid(strVal, idxStart, idxEnd - idxStart)
    End If
    strOut = strBefore & Server.MapPath(Application("FrontPage_VRoot") & strURL) & strAfter
    Application(AppVarName) = strOut
End Sub
Function FrontPage_FileExists(fspath)
    On Error Resume Next
    FrontPage_FileExists = False
    set fs = CreateObject("Scripting.FileSystemObject")
    Err.Clear
    set istream = fs.OpenTextFile(fspath)
    if Err.Number = 0 then
        FrontPage_FileExists = True
        istream.Close
    end if
    set istream = Nothing
    set fs = Nothing
End Function
</SCRIPT>

1 个答案:

答案 0 :(得分:0)

您可以使用IIS管理器将v2目录转换为应用程序。这应该激活global.asa。但是,您可能会遇到有关vroot的问题,似乎有回退到“/”

另一种选择是使用不同的主机头创建单独的网站。在这种情况下,您可以将应用程序目录v2映射到新Web,应用程序可以再次使用根目录。有关如何使用其他主机标题创建网站,请参阅http://www.youtube.com/watch?v=GK5GDkaZdLs