Thursday, March 8, 2012

ADSI Group Members and SQL

Does anyone have a good example of querying group members out of Active
Directory Group. The error seems to happen when the field I am querying has
multiple vales
This is what I have so far:
exec sp_addlinkedserver 'xxx', 'Active Directory Services 2.5',
'ADsDSOObject', 'adsdatasource'
select
convert(varchar(50), [Name]) as GroupName,
convert(varchar(500), member) as member
from openquery(xxx,
'select name, member
from ''LDAP://DC=domain,DC=com''
where objectClass = ''Group''')
This is the error message I am getting:
Server: Msg 7346, Level 16, State 2, Line 1
Could not get the data of the row from the OLE DB provider 'ADsDSOObject'.
Could not convert the data value due to reasons other than sign mismatch or
overflow.
OLE DB error trace [OLE/DB Provider 'ADsDSOObject' IRowset::GetData returned
0x40eda: Data status returned from the provider: [COLUMN_NAME=member
STATUS=DBSTATUS_E_CANTCONVERTVALUE], [COLUMN_NAME=name
STATUS=DBSTATUS_S_OK]].
Thanks,
Kevin E.Hi,
The "member" attribute is multi-valued. ADO returns this as an array. I
assume the OLE/DB driver does as well. It can have no values, one, or many.
You should test your code with all 3 possibilities. I would have to
experiment using linkedserver.
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
"KevinE" <eckart_612@.hotmail.com> wrote in message
news:tvqdnWW6j--KbwjfRVn-jg@.centurytel.net...
> Does anyone have a good example of querying group members out of Active
> Directory Group. The error seems to happen when the field I am querying
has
> multiple vales
> This is what I have so far:
> exec sp_addlinkedserver 'xxx', 'Active Directory Services 2.5',
> 'ADsDSOObject', 'adsdatasource'
>
> select
> convert(varchar(50), [Name]) as GroupName,
> convert(varchar(500), member) as member
> from openquery(xxx,
> 'select name, member
> from ''LDAP://DC=domain,DC=com''
> where objectClass = ''Group''')
>
> This is the error message I am getting:
> Server: Msg 7346, Level 16, State 2, Line 1
> Could not get the data of the row from the OLE DB provider 'ADsDSOObject'.
> Could not convert the data value due to reasons other than sign mismatch
or
> overflow.
> OLE DB error trace [OLE/DB Provider 'ADsDSOObject' IRowset::GetData
returned
> 0x40eda: Data status returned from the provider: [COLUMN_NAME=member
> STATUS=DBSTATUS_E_CANTCONVERTVALUE], [COLUMN_NAME=name
> STATUS=DBSTATUS_S_OK]].
>
> Thanks,
> Kevin E.
>
>

No comments:

Post a Comment