Solved

vb.net - getting error "Option Strict On prohibits operands of Type Object for Operator '&'"

Posted on 2008-06-11
4
1,292 Views
Last Modified: 2011-09-20
I'm attempting to read a couple of Active Directory field values (fields are distinguishedName & Description) using the Microsoft.Visual Basic Class. However, I had two sets of code I merged (one set of code had Option Strict On and the other one I forgot to turn on) caused some errors to come up.
I received the error "Option Strict On prohibits operands of Type Object for Operator '&'" on this line of code: --> objRecordSet.Fields("distinguishedName").Value) <--     and then I received this error, "AccountDisabled is not a member of 'ADODB.RecordSet'." on this line of code: --> If objAccount.AccountDisabled Then <--.
Please see code snippet below. I would appreciate any assistance on which Classes/Methods or Properites to use NOW that I've implemented Option Strict On for all the code.
Many Thanks,
WD
'If there is still an available Host record and the Host is disabled in AD, lets disable it on the database if not already.
            ElseIf IsDBNull(objRecordSet.Fields("distinguishedName").Value) = False And IsDBNull(objRecordSet.Fields("description").Value) = False Then
                While Not objRecordSet.EOF
                    Dim objAccount As ADODB.Recordset = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
                    If objAccount.AccountDisabled Then
                        ' Connect to DB and set the Status field to "Disabled" and
                        ' the Flag(soon to be DaysOffline) field to 29 days.
                        Dim sqlCon As New SqlClient.SqlConnection
                        Dim sqlCom As New SqlClient.SqlCommand
                        sqlCon.ConnectionString = My.Settings.ConnectionString
                        Try

Open in new window

0
Comment
Question by:wally_davis
  • 3
4 Comments
 

Author Comment

by:wally_davis
ID: 21769254
Ok, after making changes 40 ways from Sunday, my code now looks like this but I haven't tested it yet and I'll explain why in just a moment. Even thought I've changed this line of code, --> Dim objAccount As ADODB.Recordset = CType(GetObject("LDAP://" & CStr(objRecordSet.Fields("distinguishedName").Value)), Recordset)", <-- I still end up getting the error "AccountDisabled is not a member of 'ADODB.RecordSet'". How could a member of the ADODB.RecordSet be there one minute, but then not be there just by adding the Option Strict On for type safe language. I've already checked the methods and properties after setting Option Strict On and there is no "AccountDisabled" property. Is there another Class that I can use as its equivalent?
'If there is still an available Host record and the Host is disabled in AD, lets disable it on the database if not already.
            ElseIf IsDBNull(objRecordSet.Fields("distinguishedName").Value) = False And IsDBNull(objRecordSet.Fields("description").Value) = False Then
                While Not objRecordSet.EOF
                    Dim objAccount As ADODB.Recordset = CType(GetObject("LDAP://" & CStr(objRecordSet.Fields("distinguishedName").Value)), Recordset)
                    If objAccount.AccountDisabled Then
                        ' Connect to DB and set the Status field to "Disabled" and
                        ' the Flag(soon to be DaysOffline) field to 29 days.
                        Dim sqlCon As New SqlClient.SqlConnection
                        Dim sqlCom As New SqlClient.SqlCommand
                        sqlCon.ConnectionString = My.Settings.ConnectionString
                        Try

Open in new window

0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 21774181
Let's move to something a bit more modern and  use the built in DirectoryServices namespace.   http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx

Unfortunately, the DirectoryEntry class doesn't directly support the AccountDisabled property.... instead you'd have to check to see if the UserAccountControl property as a bit set.   Below is an example

Imports System.directoryservices

        Dim de As DirectoryEntry

        de = New DirectoryEntry("LDAP://" & objRecordSet.Fields("distinguishedName").Value.ToString)
        if CBool(Cint(dir.Properties("userAccountControl").Value) And &H2) then
0
 

Author Comment

by:wally_davis
ID: 21779952
Graye,
Is there another Object I can use vs. the Dir in the line of code that reads "(dir.Properties("userAccountControl").Value) And &H2) then"??
I'm getting an error message saying that "Properties is not a member of String" or the String "dir".
Thank you for your assistance.
0
 

Author Comment

by:wally_davis
ID: 21780037
To provide some additional insight, my objective here is to determine whether or not the distinguisheName (i.e. the Computer object) and the Description field contains the Value = DISBL in Active Directory and then perform If...Else... operations based on those conditions.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 32
Call windows 10 virtual keyboard from windows forms app 2 32
VB.NET 2008 Publish Error 2 24
Help with preventing downloading a zip file 10 35
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now