Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • Last Modified:

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?
0
johnnyjonathan
Asked:
johnnyjonathan
  • 8
  • 7
  • 2
3 Solutions
 
David Johnson, CD, MVPOwnerCommented:
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
0
 
johnnyjonathanAuthor Commented:
Thanks for the explanation, any reason why it's not working on windows 2008 R2?
0
 
David Johnson, CD, MVPOwnerCommented:
are you using sql server or mysql?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RobSampsonCommented:
Hi Johnny, can we have a look at your search filter?  Maybe it's not returning records properly....
0
 
johnnyjonathanAuthor Commented:
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
0
 
RobSampsonCommented:
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.
0
 
johnnyjonathanAuthor Commented:
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
0
 
RobSampsonCommented:
Sorry Johnny, I'll probably need to see more of the code to put it all in context.  From the snippets you're showing, it appears you are using SearchDistinguishedName to generate a recordset (via oCommand.Execute), and then only returning from that function, the DistinguishedName field value, which is only going to be a string, and not a recorset that would fill the rs object.

Alternatively, since you're returning the distinguishedName as a string, I think you would get away with using code like this (I may not have covered all of your functionality though).

Regards,

Rob.

strSANToFind = "LogonID1"
strDN = SearchDistinguishedName(strSANToFind)

If strDN <> "" Then

	Set objUser = GetObject("LDAP://" & strDN)

	If Not company = "" then
	objUser.company = CStr(company)
	end If
	
	if not title = "" then
	objUser.title = CStr(title)
	end If
	
	if not FaxNumber = "" Then
	objUser.faxnumber = CStr(FaxNumber)
	end If
	
	if not MobileNumber = "" Then
	objUser.mobile = CStr(MobileNumber)
	end If
	
	if not TelephoneExt = "" Then
	objUser.physicalDeliveryOfficeName = CStr(TelephoneExt)
	end If
	
	if not TelephoneHip = "" Then
	objUser.telephoneNumber = CStr(TelephoneHip)
	end If
	
	objUser.SetInfo
	addUsersToGroup GroupNumber,objUser.samaccountname

End If

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

0
 
johnnyjonathanAuthor Commented:
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

0
 
RobSampsonCommented:
Sorry for my delay.  I have made some small changes...see how this goes.

Regards,

Rob.

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

Const readonly = True

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Temp\Data.xls",,readonly)
objExcel.Visible = True
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 objUser = GetObject(rs(0))

			'WScript.Echo objUser.distinguishedname & vbCrLf & Username, company, title, FaxNumber, GroupNumber, MobileNumber, TelephoneExt, TelephoneHip

			If Not company = "" then
			objUser.company = CStr(company)
			end If
			
			if not title = "" then
			objUser.title = CStr(title)
			end if
			
			if not FaxNumber = "" then
			objUser.faxnumber = CStr(FaxNumber)
			end if
			
			if not MobileNumber = "" then
			objUser.mobile = CStr(MobileNumber)
			end if
			
			if not TelephoneExt = "" then
			objUser.physicalDeliveryOfficeName = CStr(TelephoneExt)
			end if
			
			if not TelephoneHip = "" then
			objUser.telephoneNumber = CStr(TelephoneHip)
			end if
			
			objUser.SetInfo
			addUsersToGroup GroupNumber,objUser.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

0
 
johnnyjonathanAuthor Commented:
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

0
 
RobSampsonCommented:
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.
0
 
johnnyjonathanAuthor Commented:
Hi Rob, yes, of course i've made the change. i'll try and update you.
0
 
johnnyjonathanAuthor Commented:
Just checked, still getting -

Using cscript and elecated command prompt -
(44, 5) Provider: The search filter cannot be recognized.
0
 
RobSampsonCommented:
I wonder if you may have an empty "username" value in your spreadsheet....try changing this
	GetUserObjectFromPartialName Username,company,title,FaxNumber,GroupNumber,MobileNumber,TelephoneExt,TelephoneHip

Open in new window


to this
	If Trim(Username) <> "" Then
		GetUserObjectFromPartialName Username,company,title,FaxNumber,GroupNumber,MobileNumber,TelephoneExt,TelephoneHip
	Else
		MsgBox "Row " & intRow & " has a blank username."
	End If

Open in new window


Regards,

Rob.
0
 
johnnyjonathanAuthor Commented:
Thanks Rob! worked like a charm!
0
 
RobSampsonCommented:
Great! Good to hear!  It's odd that 2008 treats that differently.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now