Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old September 23rd, 2004, 04:19 AM
Authorized User
 
Join Date: Sep 2004
Location: West Midlands, , United Kingdom.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nitin_sharma Send a message via Yahoo to Nitin_sharma
Default "Recordset Scope"

Hi Guys,
My first question to you all.
In VBScript
I have a recordset which is declared outside a function and in the function the recordset is used to execute and get the records.

But when I try to access the recordset values outside the function ,later in the problem it comes up with the following error :

[b][b][b]ADODB.Fields error '800a0cc1'
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.
/clubadmin/showSchoolTransfer.asp, line 169

Can anyone tell me something about the scope of a recordset.
Waiting for Reply.
Thanks
NITIN

  #2 (permalink)  
Old September 23rd, 2004, 04:30 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello Nitin,

  As long as you declare recordset at global level, it will be accessible anywhere in that page unless it is closed.

May be your error is misspelled any field name in the query. Check the field names in the query and database.
If not, post your code here.


-----------
Rajani

  #3 (permalink)  
Old September 23rd, 2004, 04:45 AM
Authorized User
 
Join Date: Sep 2004
Location: West Midlands, , United Kingdom.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nitin_sharma Send a message via Yahoo to Nitin_sharma
Default

Hi Rajani,
Thanks for the prompt reply.
If you look at the code below I execute the recordset in the fnshowschool function but when i try to access the same recordset in the sendemailfunction below it is not able to recognise that there is something in the recordset.




Response.Write fnShowSchool & "<br>"
dim rsGetSchool
set rsGetSchool = server.createobject("ADODB.recordset")
function fnShowSchool
Set sqlConn = Server.CreateObject("ADODB.Connection")
    sqlConn.Open application("vadmin_db")
    Set cmdGetSchool = Server.CreateObject("ADODB.Command")
    with cmdGetSchool
    .CommandText = "scott.school_transfer_details"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("@DfEEID", adinteger, adParamInput)
    .Parameters("@DfEEID").Value = Request.QueryString("DfEEID")
    .ActiveConnection = sqlConn
    set rsGetSchool = .Execute
    end with
    strMainBody=""
    if not rsGetSchool.EOF then
    strMainBody=strMainBody & "<tr><form name=""frmSchool"" method=post action=""showSchoolTransfer.asp?up=yes&DfEEID=" & request("DfEEID") & """>" & vbcrlf
strMainBody=strMainBody & "<tr><td bgcolor='#336699'><b>School Name:</b></td>" & vbcrlf
strMainBody=strMainBody & "<tr><td bgcolor='#336699'>&nbsp;</td><td bgcolor='#336699'><input type=""submit"" name=""submit"" value=""Transfer School""></td>" & vbcrlf strMainBody=strMainBody & "</tr></td>" & vbcrlf
    end if
    set rsGetOpp = nothing
    set cmdGetSchool = nothing
    fnShowSchool = strMainBody
    end function
    'spring clean
    set rsGetOpp = nothing
    set cmdGetOpp = nothing
    %>
    <%
    set sqlConn = Server.CreateObject("ADODB.Connection")
    sqlConn.Open application("vadmin_db")
    un = Session("Username")
    Set rsUsers = Server.CreateObject("ADODB.Recordset")
    Set rsIDs = Server.CreateObject("ADODB.Recordset")
    Set sqlConn2 = Server.CreateObject("ADODB.Connection")
    sqlConn2.Open "Driver={SQL Server}; Server=" & serverName & "; Database=GS; UID=gs_user; PWD=gs_pass"
    sqlQuery = "SELECT ID FROM BT_Users WHERE Username='" & un&"';"
    rsUsers.open sqlQuery,sqlConn2
    thisUserID = ""
    if not rsUsers.EOF Then
    thisUserID = rsUsers("ID")
    End if
    sqlQuery = "SELECT RestrictValue FROM BT_RecordAccess WHERE UserID="&thisUserID
    rsIDs.open sqlQuery,sqlConn2
    thisUserID = ""
    if not rsIDs.EOF Then
    thisUserID = rsIDs("RestrictValue")
    end if


        Set sqlConn3 = Server.CreateObject("ADODB.Connection")
    sqlConn3.Open application("vadmin_db")
    Set getclbname = Server.CreateObject("ADODB.Command")
        with getclbname
    .ActiveConnection = sqlConn
    .CommandText = "getclubname"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("@ClubID", adinteger, adParamInput) .Parameters("@ClubID").Value = thisUserID
    set rsname = .Execute
    end with


    if Request.QueryString("up") = "yes" then
    call sendemail()
    end if

    function sendemail()
    Set sendmail = Server.CreateObject("CDONTS.NewMail")
    sendmail.From = "volunteer@bt.com"
    'The mail is sent to the address
    sendmail.To = "nitin.3.sharma@bt.com"
       sendmail.Subject = "School Transfer"
    sendmail.MailFormat = 0
    'This is the content of thr message.
    sendmail.Body = "Dear Sir," & vbCrLf & vbCrLf & "The following School is requested to be transfered " & _
          vbCrlf & "School Name :" & _
          vbCrlf & "Contact Name :" & _
          vbCrlf & "Address Line 1 :" & _
          vbCrlf & "Address Line 2 :" & _
          vbCrlf & "Address Line 3 :" & _
          vbCrlf & "Country :" & _
          vbCrlf & "Post Code :" & _
      vbCrlf & "To Club Name :" & rsname("ClubName") & _
          vbCrlf & vbCrlf & "Best Regards"

     'this sets mail priority.... 0=low 1=normal 2=high
    sendmail.Importance = 2
        sendmail.Send 'Send the email!
    end function
%>

  #4 (permalink)  
Old September 23rd, 2004, 04:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Its probably because your connection goes out of scope. The recordset is declared outside the function, but its associated connection isn't.

Since you're only interested in the ClubName, why don't you just store that in a standard variable outside the function instead of the whole recordset?
  #5 (permalink)  
Old September 23rd, 2004, 05:03 AM
Authorized User
 
Join Date: Sep 2004
Location: West Midlands, , United Kingdom.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nitin_sharma Send a message via Yahoo to Nitin_sharma
Default

Hi ,
I reckon you are right that my connection is in my function where as recordset is outside.
To be honest with you I need to use all the values of recordset while sending the email.

Do you think I should get the first two statements of connection from my function and paste it outside. Not sure if it will work ??

Regards
Nitin

  #6 (permalink)  
Old September 23rd, 2004, 05:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why do you get the recordset outside the function anyway? The code you posted doesn't use it anywhere else...

If you really need it outside you could either:
1. disconnect it by setting its ActiveConnection to Nothing - you must have a client-side cursor for this to work
2. use GetRows to put the values in an array and store that array outside the function


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Scope JaneDean Beginning PHP 0 November 25th, 2008 02:07 AM
what is the scope of PHP raaj Beginning PHP 1 February 13th, 2007 12:51 AM
Scope of recordset variables James Diamond Classic ASP Databases 2 January 28th, 2004 09:37 AM
Scope of array jakeone Beginning PHP 1 November 4th, 2003 08:10 PM
scope problem jc Javascript 0 July 29th, 2003 09:27 AM





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