Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7572915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:03:08+00:00 2026-05-30T16:03:08+00:00

Go easy on me, this is my first question ;) I’ve spent a lot

  • 0

Go easy on me, this is my first question 😉

I’ve spent a lot of time looking, but I haven’t found what I’m looking for. I’ve got an intranet based reporting tool (VB.Net + ASP.Net Integrated Windows Authentication) that looks up users and managers from a SQL Server 2005 table to roll up the reporting to manager level.

This table is currently manually maintained and I’ve been asked to make it more dynamic as it is going to be up-scaled for far more users. Therefore I’m looking to link in with the Active Directory to create an Org table in the back end which will replace the current manually entered one.

I’m comfortable getting user data from the AD, but not so sure as to the best approach to set this up, I was thinking of the following table:

CREATE TABLE dbo.Employees
(
    EmpID       nvarchar(8) PRIMARY KEY,
    EmpName     nvarchar(30),
    EmpNo       nvarchar(15),
    EmpEmail    nvarChar(255),
    EmpTitle    nvarchar(255),
    MgrID       nvarchar(8) FOREIGN KEY REFERENCES Employees(EmpID)
)
GO

EmpID will be the NetworkID (sAMAccountName).

Then this will need populating from the AD, I’m guessing through recursive calls to fill in the fields.

I’m then not sure how to structure the code so that it will capture every employee under every manager starting at a given level.

I’m currently using the below to capture the direct reports for a given manager:

 Public Function GetDirectReports(ByVal ADFullName As String) As ArrayList

            Dim adItems As ArrayList = New ArrayList

            Dim rootEntry As New DirectoryEntry("LDAP://" & ADFullName)

            Dim searcher As New DirectorySearcher(rootEntry)
            searcher.PropertiesToLoad.Add("directReports")
            searcher.PropertiesToLoad.Add("sAMAccountName")
            searcher.PropertiesToLoad.Add("cn")

            searcher.PageSize = 5
            searcher.ServerTimeLimit = New TimeSpan(0, 0, 30)
            searcher.ClientTimeout = New TimeSpan(0, 10, 0)

            Dim queryResults As SearchResultCollection
            queryResults = searcher.FindAll()

            Dim x As Integer

            For Each result As SearchResult In queryResults
                For x = 0 To result.Properties("directReports").Count - 1
                    adItems.Add(New ADReports(result.Properties("directReports")(x), _
                                ExtractUser(result.Properties("directReports")(x))))
                Next
            Next
            Return adItems
        End Function

        Private Function ExtractUser(ByVal username) As String
            Return Split(Split(username, "CN=")(1), ",")(0)
        End Function

Any comments suggestions and help would be very much appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:03:09+00:00Added an answer on May 30, 2026 at 4:03 pm

    Basically what I would do is simply recurse through the entire AD and grab out all the users, with the relevant info needed, and store them in SQL Server. While enumerating, don’t worry and care about the hierarchies – you’ll handle those later.

    Once the data is inside SQL Server, you could then create e.g. a recursive CTE (Common Table Expression) to get the hierarchy of the employees – who reports to whom etc.

    As a side-note: the sAMAccountName is not guaranteed to stay stable – it could change (rare, but possible) – so maybe you need another item as the unique identifier for each user? Does your company use the userID attribute, or something else? Or could you use the AD user GUID (which will stay the same forever) instead of the samAccountName?

    Also: if you choose to stick with the sAMAccountName: be aware it could be up to 20 characters long – NVARCHAR(8) won’t be enough. Also: do you really need the Unicode strings? Those are just always twice as long as the non-Unicode VARCHAR(20) strings – just asking, you might need it, then that’s fine.

    I would probably add an artificial EmployeeID (INT IDENTITY) column to the table to handle all the requirements for a good clustering key on that table: unique, stable, narrow. A nvarchar(20) is first of all variable length which isn’t terribly good, and it could be up to 40 bytes long – which again is not optimal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Easy question this time. I'm trying to test whether or not a string does
First question here as a user, so please take it easy on this noob!
Hi guys this is my first question and i guess can be easy for
my first question here. And I'm sure it's an easy one, but I can't
This is my first question so please go easy :) I am new to
My first question here, so go easy on me. This is my situation: I
This must be an easy question but I can't find a properly answer to
Hi guys this is my first question ever on SO so please go easy
First I'm so newb to iPhone dev and I'm sorry if this is easy.
I just tried the tooltip like this Easy image preview ... But i cant

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.