dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: object required 'Server' error

  1. #1
    Join Date
    Dec 2003
    Posts
    102

    object required 'Server' error

    I am getting an error n the Server.CreateObject line in the below sub. I use this same way to connect to dbases throughout the rest of the code. Any ideas why it isnt working here?

    <script language=vbscript>
    sub getzip(txtzip)
    dim cn,rs
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open Application("OpenStr")
    set rs = Server.CreateObject("ADODB.Recordset")
    sqlstr = "SELECT county from zipcounty where zip = "+CSTR(RTRIM(LTRIM(txtzip)))
    set rs = cn.Execute(sqlstr)
    if not rs.eof then
    MyForm.tcounty.value = rs("county")
    end if
    rs.close
    set rs = nothing
    cn.close
    set cn = nothing
    end sub
    </script>

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Considering you have the HTML <srcipt> element on your page, i will assume you are trying to connect to a DB client-side.
    In that case, you cannot access the Application object from the client...

    If this script is being executed on the server, make sure you have initialised and populated the Application object.

    Regards,
    Andrew Buntine.

  3. #3
    Join Date
    Dec 2003
    Posts
    102
    Ok..I changed the sub and now I am getting a different error: Object doesn't support this property or method: 'txtzip' It seems like the parameter isnt getting populated. I call it with an ONBLUR (onblur=getzip(this)). Updated sub is below:

    <script language=vbscript>
    sub getzip(txtzip)
    Set cn1 = CreateObject("ADODB.Connection")
    openStr = "DRIVER={SQL Server};DSN=bethtest;SERVER=172.25.96.128;UID=devel;PWD=joke;"
    cn1.Open openStr
    set rs = CreateObject("ADODB.Recordset")

    sqlstr = "SELECT county FROM zipcounty WHERE zip = '" & CSTR(RTRIM(LTRIM(txtzip)))& "'"
    set rs = cn1.Execute(sqlstr)
    response.write "COUNTY: "&rs("county")
    response.write "ZIP: "&txtzip
    response.write "FORM-COUNTY: "& MyForm.tcounty.value
    if not rs.eof then
    MyForm.tcounty.value = rs("county")
    end if
    rs.close
    set rs = nothing
    cn1.close
    set cn = nothing
    end sub
    </script>

  4. #4
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Ok, you need to read the sticky at the top of this forum...

    You cannot use ASP on the client.. ASP is a server-side language so it is processed entirely on the server. Your code will simply not work.

    VBScript, however, is a client-side language. Though, it should be relied upon as it is not as widespread as javaScript.

    Regards,
    Andrew Buntine.

  5. #5
    Join Date
    Dec 2003
    Posts
    102
    I have made a change..and it now works.

  6. #6
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Good for you

    You need to rememeber that you cannot use any of ASP objects whilst using VBScript.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles