Thursday, March 29, 2012

how query Active Directory from sql2k server?

I've seen this linked server syntax many times in the group. but it
didn't work for me, maybe someone can explain it better for me?
sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',
'ADSDSOObject', 'adsdatasource'
i know that:
* " ADSI" is the server argument, which will be the name of this
linked server.
* "Active Directory Services" is the srvproduct argument, which is
the name of the OLE DB data source that you are adding as a linked
server.
* "ADSDSOObject" is the provider_name argument and indicates you
are using the OLE DB Provider.
* "adsdatasource" is the data_source argument, which is the name of
the data source as interpreted by the OLE DB Provider.
my questions are:
what "ADSDSOObject" and "adsdatasource" should be in my case? do i
need an dsn for odbc, does the AD server needs to have an instance of
sql server and so on.
for example, if i have a sql2k server call 'sql2ksvr', and an active
directory server called 'adsvr'.
exactly what step by step instructions would be to set it up in a way
that i can query the groups and users information in AD?
thank you guys!!Hi Steve
You linked server should be as is, the open query should specify your
server. See the example at:
http://msdn.microsoft.com/library/d...eneous_data.asp
And the query such as:
SELECT * FROM Openquery(ADSI, 'SELECT givenName FROM
''LDAP://192.168.0.10/OU=Aurora,DC=sales,DC=company,DC=org'' WHERE
objectCategory
= ''person'' AND objectClass = ''user''')
You will need to change the IP address (or server name) and thje OU/DC parts
.
This may also help:
http://msdn.microsoft.com/library/d...r />
_94fn.asp
John
"=== Steve L ===" wrote:

> I've seen this linked server syntax many times in the group. but it
> didn't work for me, maybe someone can explain it better for me?
> sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',
> 'ADSDSOObject', 'adsdatasource'
> i know that:
> * " ADSI" is the server argument, which will be the name of this
> linked server.
> * "Active Directory Services" is the srvproduct argument, which is
> the name of the OLE DB data source that you are adding as a linked
> server.
> * "ADSDSOObject" is the provider_name argument and indicates you
> are using the OLE DB Provider.
> * "adsdatasource" is the data_source argument, which is the name of
> the data source as interpreted by the OLE DB Provider.
>
> my questions are:
> what "ADSDSOObject" and "adsdatasource" should be in my case? do i
> need an dsn for odbc, does the AD server needs to have an instance of
> sql server and so on.
> for example, if i have a sql2k server call 'sql2ksvr', and an active
> directory server called 'adsvr'.
> exactly what step by step instructions would be to set it up in a way
> that i can query the groups and users information in AD?
> thank you guys!!
>|||i ran the following scripts on my sql2k server
script#1
sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject',
'adsdatasource'
go
script#2
SELECT * FROM
OpenQuery( ADSI, 'SELECT ADsPath FROM "LDAP://DC=MyCompany's domain
name,DC=COM" WHERE
objectClass= "user" ')
and i've got the following error
Server: Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing a query for execution against OLE DB
provider 'ADSDSOObject'.
OLE DB error trace [OLE/DB Provider 'ADSDSOObject'
ICommandPrepare::Prepare returned 0x80040e14].
is there a way to test if the linked server is working? or is there a
sample folder in AD i can query against with to see where the problems
are?
thank you.|||i finally figured how that works. i have to log into server directly
and run the query. and now i have a new question.
how to modify the following query so i can have the users and groups
they belong to? I just want to find out all the groups and users
relationship.
can some one tell me what fields available? I try to use * but it
didnt' work.
SELECT a.name, a.adspath, b.name, b.adspath
FROM OpenQuery(ADSI,
'SELECT name, ADsPath
FROM ''LDAP://shiva/ DC=MyCompany's Domain,DC=com''
WHERE objectCategory = ''person''') a,
OpenQuery(ADSI,
'SELECT name, ADsPath
FROM ''LDAP://shiva/ DC=MyCompany's Domain,DC=com''
WHERE objectCategory = ''group''') b|||Steve how did you finally get it to work because I am still getting that
error message running straight from the SQL Server.
"=== Steve L ===" wrote:

> i finally figured how that works. i have to log into server directly
> and run the query. and now i have a new question.
> how to modify the following query so i can have the users and groups
> they belong to? I just want to find out all the groups and users
> relationship.
> can some one tell me what fields available? I try to use * but it
> didnt' work.
> SELECT a.name, a.adspath, b.name, b.adspath
> FROM OpenQuery(ADSI,
> 'SELECT name, ADsPath
> FROM ''LDAP://shiva/ DC=MyCompany's Domain,DC=com''
> WHERE objectCategory = ''person''') a,
> OpenQuery(ADSI,
> 'SELECT name, ADsPath
> FROM ''LDAP://shiva/ DC=MyCompany's Domain,DC=com''
> WHERE objectCategory = ''group''') b
>

No comments:

Post a Comment