Pour accéder depuis sql server 2k à Active Directory. - Win NT/2K/XP - Windows & Software
Marsh Posté le 26-08-2004 à 11:49:41
"Le fournisseur Microsoft OLE DB pour les services d'annuaire Microsoft donne accès aux informations du service d'annuaire Microsoft® Windows® 2000. Ce fournisseur OLE DB prend en charge deux dialectes de commande, LDAP et SQL, pour accéder au service d'annuaire et renvoyer les résultats dans un format tabulaire pouvant être interrogé au moyen de requêtes distribuées SQL Server.
Pour créer un serveur lié sur le service d'annuaire de Windows 2000
Créez un serveur lié en utilisant ADSDSOObject comme provider_name et adsdatasource comme argument data_source dans la procédure stockée système sp_addlinkedserver.
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject', 'adsdatasource'
GO
Pour les connexions Windows authentifiées, le mappage automatique est suffisant pour accéder à l'annuaire en utilisant la délégation de sécurité de SQL Server. Le mappage automatique étant créé par défaut pour les serveurs liés créés au moyen de sp_addlinkedserver, aucun autre mappage de connexion n'est nécessaire.
Pour les connexions SQL Server authentifiées, des identifications de connexion/mots de passe adéquats peuvent être configurés pour la connexion au service d'annuaire en utilisant la procédure stockée du système sp_addlinkedsrvlogin.
Interrogation du service d'annuaire
Le fournisseur Microsoft OLE DB pour les services d'annuaire Microsoft prend en charge deux dialectes de commande, LDAP et SQL, pour interroger le service d'annuaire. La fonction OPENQUERY peut être employée pour envoyer une commande au service d'annuaire et utiliser ses résultats dans une instruction SELECT.
L'exemple suivant illustre la création d'une vue qui utilise OPENQUERY pour renvoyer des informations de l'annuaire sur le serveur ADSISrv dont l'adresse de domaine est sales.northwind.com. La commande dans la fonction OPENQUERY est une requête SQL sur l'annuaire pour renvoyer les attributs Name, SN et ST des objets appartenant à la classe Contact à une position hiérarchique spécifiée (OU=Sales) dans l'annuaire. La vue peut maintenant être employée dans n'importe quelle requête SQL Server.
CREATE VIEW viewADContacts
AS
SELECT [Name], SN [Last Name], ST State
FROM OPENQUERY( ADSI,
'SELECT Name, SN, ST
FROM ''LDAP://ADSISrv/ OU=Sales,DC=sales,DC=northwind,DC=com''
WHERE objectCategory = ''Person'' AND
objectClass = ''contact''')
GO
SELECT * FROM viewADContacts"
voili voilou
Marsh Posté le 26-08-2004 à 13:39:02
wuxiu a écrit : "Le fournisseur Microsoft OLE DB pour les services d'annuaire Microsoft donne accès aux informations du service d'annuaire Microsoft® Windows® 2000. Ce fournisseur OLE DB prend en charge deux dialectes de commande, LDAP et SQL, pour accéder au service d'annuaire et renvoyer les résultats dans un format tabulaire pouvant être interrogé au moyen de requêtes distribuées SQL Server. |
Merci beaucoup pour ces indications mais hélas ça ne marche pas chez moi ...
Déjà ce qui me chiffonne c'est l'argument "adsdatasource" qui semble venir de nulle part mais qu'on retrouve partout dans les aides, mais qu'on ne définit pas vraiment ...
Néanmoins mon problème vient peut-être du fait que mon annuaire AD se trouve sur Windows Server 2003 et pas sur 2000 ...
Voilà l'erreur quand j'essaie de passer par le serveur lié pour créer la vue en question :
Citation : Erreur lors de la préparation de la requête à exécuter sur le fournisseur OLE DB 'ADSDSOObject'. |
Marsh Posté le 26-08-2004 à 14:30:50
Creating a Linked Server to the Active Directory
Top
Microsoft Developers Network posts the article MSDN Library: OLE DB Provider for Microsoft Directory Services on querying an AD, which is a good place to start. For some strange reason I did not immediately recognize the reference to adsdatasource, when using the sp_addlinkedserver stored procedure, as a placeholder for the name of the domain when targeting an Active Directory source. There are actually several sources which are applicable here. I would assume that any LDAP data source is valid, including Exchange Server. As a newbie to using SQL Server to talk to an Active Directory, I had a particularly difficult time following the Microsoft Documentation.
When talking to an Active Directory programmatically, it is often ideal not to have to hard code information about the Forest or Trees in the domain structure. In a perfect world, it is helpful to learn what specific domains you can talk to by first asking a general question.
The first line of T-SQL code creates a linked server connection in SQL Server using ADsDSOObject to talk to the RootDSE the root of the AD forest. Notice that argument, adsdatasource, for the stored procedure sp_addlinkedserver, has been replaced with RootDSE, this is something which did not register in my head for some time, and judging from other online posts on this issues, is a common problem. By using RootDSE as the data source, an LDAP query can be built to return data about the domain structure itself. This is particularly useful when the structure changes over time, as applications now have the ability to be aware of the dynamic structure without recompilation by changing hard-coded values.
Exec sp_addlinkedserver 'ADRoot', 'Active Directory Services 2.5',
'ADsDSOObject', 'RootDSE'
Also note, the name of the linked server is ADRoot and not ADSI as is noted in MSDN documentation. You are free to name this anything you like, within the limits of SQL Server and the sp_addlinkedserver stored procedure call. Also note that you can drop a linked server by calling the next line of code.
exec sp_dropserver 'ADRoot'
If you know the name of the domain you wish to query against, often you can simply use that as the adsdatasource data argument.
To create a link to a specific domain, WestDom in these examples, you can execute a sp_addlinkedserver call like the following, which creates a link with the name ADWest with which we now can execute LDAP commands against.
Exec sp_addlinkedserver 'ADWest', 'AD Services for Big Corp Domain',
'ADsDSOObject', 'WestDom'
in : http://www.nerva.com/Computing/Cod [...] xample.htm
Marsh Posté le 26-08-2004 à 16:40:44
Merci, au moins ça m'en dit plus ce dsn qui semble venir de nulle part.
J'en ai profité pour mettre la dernière version de MDAC sur ma machine.
Malheureusement j'ai toujours le même message d'erreur.
Marsh Posté le 26-08-2004 à 09:22:42
Bonjour,
La recherche ne fonctionnant pas, je tente ma chance pour savoir si quelqu'un est déjà arrivé à accéder aux données de l'annuaire Active Directory depuis sql server 2000.
En gros il suffit de créer un serveur lié mais malheureusement il faut définir un dsn vers cet annuaire et pour l'instant je n'ai rien trouvé de probant
Donc si quelqu'un pouvait m'éclairer ... Merci d'avance.