title: ASP and LDAP: The connection cannot be used to perform this operation. It is either closed or invalid in this context.
body: <p>Continuing with ASP, I have sine code which gives the user a form, which displays data currently held in Active Directory, and lets the user update some of their details. I have tried everything but am stil getting the error</p>
  
  <p>"ADODB.Command error '800a0e7d' </p>
  
  <p>The connection cannot be used to perform this operation. It is either closed or invalid in this context. </p>
  
  <p>/editentry.asp, line 31"</p>
  
  <p>Anyway, my code isL</p>
  
  <pre><code>&lt;%@ Language=VBScript  %&gt;
  &lt;% response.Buffer = True
  'Define the AD OU that contains our users
  
  
  dim ADUser, user, firstname, lastname, email, telephonenumber, mobile
  'This initializes all of our variables
  
  
  user = request.querystring("account_name")
  'This puts the value of the account_name into a variable
  if len(user) = 0 then
  'If the length of the username is equal to 0
               response.write "Please supply a username in the query string" 
  
  elseif len(user) &gt; 0 then
  'Else is length of user is greater than 0
              ADUser = "LDAP://OU=Staff,OU=Users,DC=Something,DC=internal"
             ' Make AD connection and run query
               Set objCon = Server.CreateObject("ADODB.Connection")
               objCon.provider ="ADsDSOObject"
               objCon.Properties("User ID") = "EXAMPLE\Testuser"
              objCon.Properties("Password") = "TestUser1!"
             objCon.Properties("Encrypt Password") = TRUE
          objCon.open "Active Directory Provider"
      Set objCom = CreateObject("ADODB.Command")
    objCom.CommandText ="select ADsPath, givenName,sn,mail,telephonenumber,mobile,sAMAccountName FROM '"+ ADUser +"' where sAMAccountname='"&amp; user &amp; "'"
        'objCom.Properties("searchscope") = ADS_SCOPE_ONELEVEL
  
      Set objRS = objCom.Execute
  
       ' Loop over returned recordset and output HTML
  
      Response.Write vbCrLf
  Do While Not objRS.EOF Or objRS.BOF
  Response.Write " &lt;form action='editentry.asp?account_name=" + user + "' method='POST'&gt;"
  Response.Write "&lt;p&gt;&lt;label for='firstname'&gt;Firstname&lt;/label&gt;&lt;input type='text' id='firstname' value='" + objRS("givenName") +"' name='fname'&gt;&lt;/p&gt;"
  Response.Write "&lt;p&gt;&lt;label for='lastname'&gt;Lastname&lt;/label&gt;&lt;input type='text' id='lastname' value='" + objRS("sn") +"' name='lname'&gt;&lt;/p&gt;"
            Response.Write "&lt;p&gt;&lt;label for='mail'&gt;E-Mail Address&lt;/label&gt;&lt;input type='text' id='lastname' value='" + objRS("mail") +"' name='email'&gt;&lt;/p&gt;"
            Response.Write "&lt;p&gt;&lt;label for='mobile'&gt;Mobile&lt;/label&gt;&lt;input type='text' id='mobile' value='" + objRS("mobile") +"' name='mobile'&gt;&lt;/p&gt;"
            Response.Write "&lt;p&gt;&lt;label for='telephone'&gt;Telephone Number&lt;/label&gt;&lt;input type='text' id='email' value='" + objRS("telephonenumber") +"' name='telephonenumber'&gt;&lt;/p&gt;"
            Response.Write "&lt;p&gt;&lt;input type='hidden' id='subval' value='1' name='subval'&gt;&lt;/p&gt;"
            Response.Write "&lt;p&gt;&lt;input type='submit' name='submit'&gt;&lt;input type='reset' name='reset'&gt;&lt;/p&gt;"
             Response.Write "&lt;/form&gt;" + vbCrLf
             objRS.MoveNext
              Response.Flush
  Loop
  
  if isEmpty(request.form("subval"))=FALSE then 
  'Subval will contain 1 if the form is submitted, else it won't exist, so we can check the form has been submitted by reading it back
  firstname = request.form("fname")
  lastname = request.form("lname")
  email = request.form("email")
  mobile = request.form("mobile")
  telephonenumber = request.form("telephonenumber")
  Do While Not objRS.EOF
          Set usr = GetObject(objRS.Fields("ADsPath").Value)
         usr.Put "gjvenName", firstname
         usr.Put "sn", lastname
         usr.Put "mail", email
         usr.Put "mobile", mobile
         usr.Put "telephonenumber", telephonenumber
         usr.SetInfo
        objRS.MoveNext
  loop
  
  
   response.write "Entry has been updated "
  
  end if
  end if
  ' Clean up
        objRS.Close
        objCon.Close
       Set objRS = Nothing
      Set objCon = Nothing
      Set objCom = Nothing
  </code></pre>
  
  <p>%></p>
  
  <p>I'm not sure what is wrong here </p>