Link to home
Start Free TrialLog in
Avatar of johnnyjonathan
johnnyjonathan

asked on

rs.EOF not working in Windows 2008R2 under VBSCRIPT

Hi,

I have the following code:

<%
.... VBSCRIPT ...
If Not rs.EOF Then
... Do something...
End If
%>

I'm not familiar with what rs.EOF is and would appreciate if someone can explain to me what it is?

But the problem is, that what ever it is, it's working on Windows Server 2003 and fails to work on Windows 2008 R2 under this error -

Error:      The search filter cannot be recognized.
Code:      8007203E
Source:      Provider
System:      The search filter cannot be recognized.


Can anyone please assist?
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

rs.EOF its a boolean.. that means if the query executes right it returns true, otherwise it returns false
i.e.
   
Set rs=con.execute("Select * from login where username='"&username&"' AND password='"&password&"' AND flag='yes'")
        If rs.EOF Then
                Response.Redirect("index.error.asp?Error=Login_Failed!")
                else
                            Set rs=con.execute("Select userlevel from login where username='"&username&"' AND password='"&password&"' AND flag='yes'")

Open in new window

http://www.ozzu.com/programming-forum/what-eof-asp-t79243.html
Avatar of johnnyjonathan
johnnyjonathan

ASKER

Thanks for the explanation, any reason why it's not working on windows 2008 R2?
are you using sql server or mysql?
Hi Johnny, can we have a look at your search filter?  Maybe it's not returning records properly....
If Not rs.EOF Then
        Set GetUserObjectFromPartialName = GetObject(rs(0))
                  
                  If Not company = "" then
                  GetUserObjectFromPartialName.company = CStr(company)
                  end if
                  
                  if not title = "" then
                  GetUserObjectFromPartialName.title = CStr(title)
                  end if
                  
                  if not FaxNumber = "" then
                  GetUserObjectFromPartialName.faxnumber = CStr(FaxNumber)
                  end if
                  
                  if not MobileNumber = "" then
                  GetUserObjectFromPartialName.mobile = CStr(MobileNumber)
                  end if
                  
                  if not TelephoneExt = "" then
                  GetUserObjectFromPartialName.physicalDeliveryOfficeName = CStr(TelephoneExt)
                  end if
                  
                  if not TelephoneHip = "" then
                  GetUserObjectFromPartialName.telephoneNumber = CStr(TelephoneHip)
                  end if
                  
                  GetUserObjectFromPartialName.SetInfo
                  addUsersToGroup GroupNumber,GetUserObjectFromPartialName.samaccountname

                  
    End If
That doesn't appear to be the search filter (or query) that is being used to generate the recordset.  Can you post the CommandText you are using to get the recordset?

Rob.
Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob,
Full script listed below -

dim FirstNameAD
dim LastNameAD
dim company
dim title
dim FaxNumber
dim Username
dim GroupNumber
dim MobileNumber
dim TelephoneExt
dim TelephoneHip

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Data.xls",,readonly)
intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
	company = objExcel.Cells(intRow, 1).Value
	FirstNameAD = objExcel.Cells(intRow, 2).Value
	LastNameAD = objExcel.Cells(intRow, 3).Value
	title = objExcel.Cells(intRow, 4).Value
	FaxNumber = objExcel.Cells(intRow, 10).Value
	Username = objExcel.Cells(intRow, 12).Value
	GroupNumber = objExcel.Cells(intRow, 6).Value
	MobileNumber = objExcel.Cells(intRow, 8).Value
	TelephoneExt = objExcel.Cells(intRow, 9).Value
	TelephoneHip = objExcel.Cells(intRow, 13).Value
	

	GetUserObjectFromPartialName Username,company,title,FaxNumber,GroupNumber,MobileNumber,TelephoneExt,TelephoneHip
	intRow = intRow + 1
Loop
objWorkBook.Close 
objExcel.Quit


Public Function GetUserObjectFromPartialName(Username,company,title,FaxNumber,GroupNumber,MobileNumber,TelephoneExt,TelephoneHip)
 '   on Error Resume Next
	Set rs = CreateObject("adodb.recordset")
    rs.ActiveConnection = "provider=adsdsoobject"	
	rs.Open "<LDAP://dc=contoso,dc=com>;(&(objectCategory=user)(SamAccountName=" & Username & "));adspath;subtree"
    If Not rs.EOF Then
        Set GetUserObjectFromPartialName = GetObject(rs(0))
			
			If Not company = "" then
			GetUserObjectFromPartialName.company = CStr(company)
			end if
			
			if not title = "" then
			GetUserObjectFromPartialName.title = CStr(title)
			end if
			
			if not FaxNumber = "" then
			GetUserObjectFromPartialName.faxnumber = CStr(FaxNumber)
			end if
			
			if not MobileNumber = "" then
			GetUserObjectFromPartialName.mobile = CStr(MobileNumber)
			end if
			
			if not TelephoneExt = "" then
			GetUserObjectFromPartialName.physicalDeliveryOfficeName = CStr(TelephoneExt)
			end if
			
			if not TelephoneHip = "" then
			GetUserObjectFromPartialName.telephoneNumber = CStr(TelephoneHip)
			end if
			
			GetUserObjectFromPartialName.SetInfo
			addUsersToGroup GroupNumber,GetUserObjectFromPartialName.samaccountname

			
    End If
End Function

'==========================================================
' Add users to the group
'==========================================================
public function addUsersToGroup(GroupNumber,username)
	on Error Resume Next
	Dim objGroup    ' Object representing group
	Dim GroupDn
	

	if GroupNumber = "1" then
		GroupDn = "CN=Signature1,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "2" then
		GroupDn = "CN=Signature2,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "3" then
		GroupDn = "CN=Signature3,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "4" then
		GroupDn = "CN=Signature4,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "5" then
		GroupDn = "CN=Signature5,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "6" then
		GroupDn = "CN=Signature6,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "7" then
		GroupDn = "CN=Signature7,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "8" then
		GroupDn = "CN=Signature8,OU=Groups,dc=contoso,dc=com"
	end if
	if GroupNumber = "9" then
		GroupDn = "CN=Signature9,OU=Groups,dc=contoso,dc=com"
	end if
	
	' Create group object

DNUSERNAME = SearchDistinguishedName (username)
'WScript.Echo DNUSERNAME

	
	Set	objGroup1 = GetObject("LDAP://" & "CN=Signature1,OU=Groups,dc=contoso,dc=com")
	objGroup1.Remove("LDAP://" & DNUSERNAME)

	Set objGroup2 = GetObject("LDAP://" & "CN=Signature2,OU=Groups,dc=contoso,dc=com")
	objGroup2.Remove("LDAP://" & DNUSERNAME)

	Set objGroup3 = GetObject("LDAP://" & "CN=Signature3,OU=Groups,dc=contoso,dc=com")
	objGroup3.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup4 = GetObject("LDAP://" & "CN=Signature4,OU=Groups,dc=contoso,dc=com")
	objGroup4.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup5 = GetObject("LDAP://" & "CN=Signature5,OU=Groups,dc=contoso,dc=com")
	objGroup5.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup6 = GetObject("LDAP://" & "CN=Signature6,OU=Groups,dc=contoso,dc=com")
	objGroup6.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup7 = GetObject("LDAP://" & "CN=Signature7,OU=Groups,dc=contoso,dc=com")
	objGroup7.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup8 = GetObject("LDAP://" & "CN=Signature8,OU=Groups,dc=contoso,dc=com")
	objGroup8.Remove("LDAP://" & DNUSERNAME)

	Set objGroup9 = GetObject("LDAP://" & "CN=Signature9,OU=Groups,dc=contoso,dc=com")
	objGroup9.Remove("LDAP://" & DNUSERNAME)
	
	Set objGroup100 = GetObject("LDAP://" & GroupDn)
	objGroup100.Add("LDAP://" & DNUSERNAME)
	
End Function




Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob, i have progress, the excel is opened, but i get -

Line:	44
Column:	5
Error:	The search filter cannot be recognized.
Code:	8007203E
Source:	Provider

System:	The search filter cannot be recognized.

Open in new window

Just to confirm, I assume you have changed
dc=contoso,dc=com

to the relevant domain name for your domain?

Try running this script from a pure VBS file (if you're not already) and run it from an elevated command prompt using
cscript C:\Scripts\VBS1.vbs

The query works for me, so I'm a little confused as to why you'd see a search filter error....

Rob.
Hi Rob, yes, of course i've made the change. i'll try and update you.
Just checked, still getting -

Using cscript and elecated command prompt -
(44, 5) Provider: The search filter cannot be recognized.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rob! worked like a charm!
Great! Good to hear!  It's odd that 2008 treats that differently.