
ADO.Net to fetch ActiveDirectory this function bugs in Asp.net but works in Vb.n
Hi !!
I've written this generic function that receive in
arguments: an LDAP query, UserId and Password. It creates
connection, fills a dataset and returns the dataset. Used
in my VB code, it works but when I used it in ASP.net code
or as a WebService, it fails each time with the
error: "DB_E_NOTABLE(0x80040E37)."
I tried to change the "Provider=ADsDSOObject" string but
the error message changed so I tried to change the "Data
Source=Active Directory Provider" string and there, the
error message did not change so I'm wondering if the
problem wouldn't the data source...
Is there a way to know if that datasource is available on
my server and how to install it
Thanks for any help,
Claude Vernier
As an example, this query is supposed to be working:
SELECT distinguishedName
FROM 'LDAP://myadserver:404/ou=People,dc=cvi,dc=hyrule,dc=c
om' WHERE objectClass='CVIperson' AND cn='gandalf'
'Feel free to use this function in your VB.NET code to
fetch AD data using ADO.NET
Public Function CreateDataSetForActiveDirectory(ByVal
sQuery As String, Optional ByVal sUid As String
= "anonymous", Optional ByVal sPwd As String
= "anonymous") As System.Data.DataSet
Dim oOleDbDataSet As New System.Data.DataSet()
Try
Dim oOleDbConn As System.Data.OleDb.OleDbConnection
Try
oOleDbConn = New System.Data.OleDb.OleDbConnection
("Provider=ADsDSOObject;" & _
"Data Source=Active Directory Provider;" & _
"User ID=" & sUid & ";" & _
"Password=" & sPwd)
Dim adapter As New System.Data.OleDb.OleDbDataAdapter()
Try
adapter.SelectCommand = New System.Data.OleDb.OleDbCommand
(sQuery, oOleDbConn)
adapter.Fill(oOleDbDataSet)
Catch exOleDb As System.Data.OleDb.OleDbException
debug.print "exOleDb created: " & exOleDb.Message
Dim oErr As System.Data.OleDb.OleDbError
For Each oErr In exOleDb.Errors
debug.print "OleDb Error occured: " & oErr.Message
Next
Catch ex As Exception
debug.print "Error occured in SelectCommand or Fill: " &
ex.Message
oOleDbDataSet = Nothing
End Try
Catch ex As Exception
debug.print "Error occured in New Command: " & ex.Message
oOleDbDataSet = Nothing
Finally
Try
oOleDbConn.Close()
Catch ex As Exception
debug.print "Error occured in Closing Connection: " &
ex.Message
oOleDbDataSet = Nothing
End Try
End Try
Catch ex As Exception
debug.print "Error occured in Dim oOleDbConn As
System.Data.OleDb.OleDbConnection: " & ex.Message
oOleDbDataSet = Nothing
End Try
Return oOleDbDataSet
End Function