The database connection named 'Candidates' is undefined.

Posted on 2006-05-11
Last Modified: 2013-12-24

Could you please assist me with an issue that both my ISP and Microsoft Australia are unable to resolve.  It relates to FP2003 and the following error:

The database connection named 'Candidates' 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

My global.asa pages reads as follows:

Sub Application_OnStart
      '==FrontPage Generated - startspan==
      Dim FrontPage_UrlVars(1)
      '--Project Data Connection
            Application("Candidates_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/database5.mdb"
            FrontPage_UrlVars(0) = "Candidates_ConnectionString"
            Application("Candidates_ConnectionTimeout") = 15
            Application("Candidates_CommandTimeout") = 30
            Application("Candidates_CursorLocation") = 3
            Application("Candidates_RuntimeUserName") = ""
            Application("Candidates_RuntimePassword") = ""
      Application("FrontPage_UrlVars") = FrontPage_UrlVars
      '==FrontPage Generated - endspan==
End Sub
Sub Session_OnStart
      FrontPage_StartSession '==FrontPage Generated==
      FrontPage_ConvertFromODBC '==FrontPage Generated==
End Sub
Sub FrontPage_StartSession
      On Error Resume Next
      if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub
      sFile = "global.asa"
      sRootPath = Request.ServerVariables("APPL_PHYSICAL_PATH")
      if Left(sRootPath,1) = "/" then sSep = "/" else sSep = "\"
      if Right(sRootPath,1) <> sSep then sRootPath = sRootPath & sSep
      sRootPath = sRootPath & sFile
      ' discover the VRoot for the current page;
      ' walk back up VPath until we match VRoot
      Vroot = Request.ServerVariables("PATH_INFO")
      iCount = 0
      do while Len(Vroot) > 1
            idx = InStrRev(Vroot, "/")
            if idx > 0 then
                  Vroot = Left(Vroot,idx)
                  ' error; assume root web
                  Vroot = "/"
            end if
            if Server.MapPath(Vroot & sFile) = sRootPath 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
      ' map all URL= attributes in _ConnectionString variables
      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))
      end if
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)
            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
Sub FrontPage_ConvertFromODBC
      On Error Resume Next
      if Len(Application("ASP_OS")) > 0 then exit sub
      str = "_ConnectionString"
      slen = Len(str)
      set oKnown = Server.CreateObject("Scripting.Dictionary")
      oKnown.Add "DRIVER",""
      oKnown.Add "DBQ",""
      oKnown.Add "SERVER",""
      oKnown.Add "DATABASE",""
      oKnown.Add "UID",""
      oKnown.Add "PWD",""
      For each item in Application.Contents
            if UCase(Right(item,slen)) = UCase(str) then
                  sName = Left(item,Len(item)-slen)
                  sConn = Application(item)
                  if InStr(LCase(sConn),"provider=") < 1 and Len(Application(sName & "_ConnectionTimeout"))>0 then
                        sArr = Split(sConn,";")
                        set oDict = Server.CreateObject("Scripting.Dictionary")
                        bUnknown = False
                        for i = 0 to UBound(sArr)
                              s = sArr(i)
                              idx = InStr(s,"=")
                              sKey = UCase(Trim(Left(s,idx-1)))
                              sVal = Trim(Mid(s,idx+1))
                              oDict.Add sKey, sVal
                              if Not oKnown.Exists(sKey) then bUnknown = True
                        if bUnknown = False and oDict.Exists("DRIVER") then
                              sDrv = oDict.Item("DRIVER")
                              sNew = ""
                              if InStr(sDrv,"Microsoft Access") > 0 and oDict.Exists("DBQ") and not (oDict.Exists("UID") or oDict.Exists("PWD")) then
                                    sNew = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & oDict.Item("DBQ")
                              elseif InStr(sDrv,"SQL Server") > 0 and oDict.Exists("SERVER") and oDict.Exists("DATABASE") then
                                    sNew = "Provider=SQLOLEDB;Data Source=" & oDict("SERVER") & ";Initial Catalog=" & oDict("DATABASE")
                                    if oDict.Exists("UID") then sNew = sNew & ";User ID=" & oDict("UID")
                                    if oDict.Exists("PWD") then sNew = sNew & ";Password=" & oDict("PWD")
                              end if
                              if sNew <> "" then
                                    Application(item) = sNew
                              end if
                        end if
                        set oDict = Nothing
                  end if
            end if
      Set oKnown = Nothing
End Sub
<head><title>Web Site Settings for Active Server Pages</title><html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<!--[if gte mso 9]><xml>
<mso:connectionstatus msdt:dt="string">Candidates=1</mso:connectionstatus>

If you could rectify this issue, I'd be greatly appreciated as no-one else can.
Question by:goldie65
    LVL 2

    Accepted Solution

    Now this is a hard one - If MS could not solve it, who am I to try. ;-) well lets give it a go!

    1st try adding this line below the first Sub Session_onstart --- Make sure you have backed up your original global.asa

    session("Candidates_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/database5.mdb; APP=ASP Script"


    Session("Candidates_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/database5.mdb"

    2nd try, Avoid typing in your queries. Click on the space you want to return your record. select Database - results From Insert menu.  Click on create new connection, Add, Give it a new name. with browse trace the access DB. Verify and always use the wizard.

    Lastly if you must type in your code youself. Trace the offending page (there has to be a page where you have typed in asp code to fetch data from this db- and simplyfy your conncetion code like this

    <% Set objDC = server.createObject("ADODB.Connection")
    objDC.Open Application("Candidate_connectionstring")
    set objRS = objDC.execute(Select * from yourTable")%>

    <% Do Until objRS.EOF

    objRS("Name")  'reapeat this for other columns in your table

    Set objRS = Nothing
    objDC = Nothing

    Author Comment

    Hi Eme,

    Thanks for your response' you're not going to believe this.  It was as simple as a pathing error and nothing more

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Now that Expression Web 4.0 ( is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
    This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
    The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
    The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now