Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 12th, 2005, 02:49 PM
Registered User
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default MS Access & ASP

I'm trying to use a database to store data from forms and for logon purposes, but it seems i am unable to add new data to the database via the form any help is very welcome

I have included the code and the name of the containing file

' FP_ASP ASP Automatically generated by a FrontPage Component. Do not Edit.

On Error Resume Next
Session("FP_OldCodePage") = Session.CodePage
Session("FP_OldLCID") = Session.LCID
Session.CodePage = 1252
Session.LCID = 1033

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then

    Set fp_conn = Server.CreateObject("ADODB.Connection")
    FP_DumpError strErrorUrl, "Cannot create connection"

    Set fp_rs = Server.CreateObject("ADODB.Recordset")
    FP_DumpError strErrorUrl, "Cannot create record set"

    fp_conn.Open Application("_ConnectionString")
    FP_DumpError strErrorUrl, "Cannot open database"

    fp_rs.Open "", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
    FP_DumpError strErrorUrl, "Cannot open record set"

    FP_DumpError strErrorUrl, "Cannot add new record set to the database"
    Dim arFormFields0(0)
    Dim arFormDBFields0(0)
    Dim arFormValues0(0)

    FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

    FP_DumpError strErrorUrl, "Cannot update the database"


    FP_FormConfirmation "text/html; charset=windows-1252",_
                        "Form Confirmation",_
                        "Thank you for submitting the following information:",_
                        "Return to the form."

End If
End If

Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")

<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<TITLE>New Page 1</TITLE>

<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">
Please provide the following contact information:</P>
<TD ALIGN="right">
<INPUT TYPE=TEXT NAME="Contact_FullName" SIZE=35>
<TD ALIGN="right">
<INPUT TYPE=TEXT NAME="Contact_Title" SIZE=35>
<TD ALIGN="right">
<INPUT TYPE=TEXT NAME="Contact_Organization" SIZE=35>
<TD ALIGN="right">
<EM>Work Phone</EM></TD>
<TD ALIGN="right">
<TD ALIGN="right">
<INPUT TYPE=TEXT NAME="Contact_Email" SIZE=25>
<TD ALIGN="right">

<a href="index.htm">Home</a></H5>
<a href="data-code.htm.htm">View Code</a></p>

Sub Application_OnStart
    '==FrontPage Generated - startspan==
    Dim FrontPage_UrlVars(1)
    '--Project Data Connection
        Application("data_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/data.mdb"
        FrontPage_UrlVars(0) = "data_ConnectionString"
        Application("data_ConnectionTimeout") = 15
        Application("data_CommandTimeout") = 30
        Application("data_CursorLocation") = 3
        Application("data_RuntimeUserName") = ""
        Application("data_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></head>

The Following User Says Thank You to c.j.rowell@ntlworld.com For This Useful Post:
Ramkumar Bishnoi (April 24th, 2011)

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access .mdb & .ldb database corrupted faisal573 Access 17 December 6th, 2017 04:38 AM
Events with VBA & MS Access hoen VB How-To 0 January 19th, 2006 10:18 PM
MS SQL 2000 & ASP Adam H-W Classic ASP Databases 3 August 22nd, 2005 07:58 AM
ASP.NET & MS Word Napoline .NET Web Services 1 May 11th, 2004 07:09 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.