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 8172957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:57:36+00:00 2026-06-06T21:57:36+00:00

Ok so we have some tables in SQL that identifies users by their Guid

  • 0

Ok so we have some tables in SQL that identifies users by their Guid from active directory. Originally the dev team wanted to just mirror the user base in sql, but the manager insists that we keep it in active directory. So at any rate, one of the operations that we’re trying to perform is taking a a table from SQL that contains the user’s Guid and some other information and join that to a table that is being generated from an openquery to AD.

The problem is that if a user gets deleted from AD, the open query pukes. I’m assuming it is because we’re attempting to navigate to an entry in active directory that doesn’t exist and since it isn’t an actual query (it’s an index, essentially), its blowing up. This is the ldap string that we’re using to pull the user

LDAP://<GUID=(guid here)>

or more specifically, something like

SELECT * from openquery(ADSI, '
   SELECT displayName, mail
   FROM LDAP://<GUID=(userGuid)>
')

Now if this were a query instead of an index, or in this case a “filter”, (objectGuid=x) would simply return no results instead of throwing an error. But the problem here is that objectGuid doesn’t come back to SQL as a guid, it comes back as a binary 0x102938102938 or some garbage. Now, i thought of maybe converting the Guid to hex then to binary and then attempting to query AD with that, but I dont even know where to start.

So I guess the ultimate question here is: how do i query active directory for a user by guid, without it throwing an error if that guid doesn’t exist? This way I can join it to a sql query? This needs to be achievable in T-SQL, not in code using the .net DirectoryServices helpers.

I apologize if this seems scatter brained, I just wanted to put up here what we’ve been dealing with. Any input is appreciated, including suggestions for taking a different route. TIA

  • 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-06-06T21:57:42+00:00Added an answer on June 6, 2026 at 9:57 pm

    So a couple of things:

    As far as formatting your GUID, you’re going to want to do a CAST(yourColumn as varchar(38)). This link explains the formats that work – http://msdn.microsoft.com/en-us/library/windows/desktop/ms677985(v=vs.85).aspx. I don’t know offhand (if/how) you can tell SQL how to format the casted value. You may need to dig up a function online that will do GUID formatting for you.

    I would suggest for your join that you see if you can do your AD lookup in a table valued function, you can trap errors there and return no rows or return the row and join that way.

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

Sidebar

Related Questions

I have some tables that benefit from many-to-many tables. For example the team table.
Say we have some poorly written SQL that does not release temp tables when
I'm using SQL Server (2005). Today I have some tables that everytime the data
I am using Sql database and I have indexed some tables. In some tables
I have a SQL server and couple Windows clients and cache of some tables
i have made columns in some of the tables encrypted in sql server 2008.
Preamble: I'm creating some tables in SQL Server that will be accessed via Linq-to-entities
Some background: I have an database that I want to use linq-to-sql to update
I have some data in an SQL table with an XML datatype column where
Trying to have my PHP script return some SQL table queries. Here's my script

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.