ADSI Query

  • Thread starter Thread starter Adam Hafner
  • Start date Start date
A

Adam Hafner

I am attempting to use the System.Data.OleDb namespace to
connect to an Active Directory running under Win2000. I
have initialized the OleDbConnection with a connection
string of "Provider=ADSDSOObject;". I have a simple query
string as follows: "SELECT sAMAccountName
FROM 'LDAP://mydomain.com/' WHERE objectClass = 'User'"

I receive an errror when I try to read the
results: "OleDbDataReader result = myCommand.ExecuteReader
(CommandBehavior.CloseConnection);"

The error states: DB_E_ERRORSINCOMMAND(0x80040E14) - An
unhandled exception occurred during the execution of the
current web request.

Any samples or suggestions are greatly appreciated.

Thanks!
 
¤ I am attempting to use the System.Data.OleDb namespace to
¤ connect to an Active Directory running under Win2000. I
¤ have initialized the OleDbConnection with a connection
¤ string of "Provider=ADSDSOObject;". I have a simple query
¤ string as follows: "SELECT sAMAccountName
¤ FROM 'LDAP://mydomain.com/' WHERE objectClass = 'User'"
¤
¤ I receive an errror when I try to read the
¤ results: "OleDbDataReader result = myCommand.ExecuteReader
¤ (CommandBehavior.CloseConnection);"
¤
¤ The error states: DB_E_ERRORSINCOMMAND(0x80040E14) - An
¤ unhandled exception occurred during the execution of the
¤ current web request.
¤
¤ Any samples or suggestions are greatly appreciated.

In addition to the other suggestions, I would first try to trap the error using Try...Catch. I
haven't heard anything that indicates that the AD provider is not supported by the OLEDB .NET
provider.

There are different ways to query but I've typically used the default naming context. In my instance
it's: LDAP://DC=testdomain,DC=org but you should be able to use DirectoryServices to extract this
information.

Also, I would try removing the CommandBehavior.CloseConnection argument to see if it makes any
difference.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul,

Thanks for responding to my post. I noticed that you had
similiar problems with ADO.NET from your posting on .Net
247
(http://www.dotnet247.com/247reference/msgs/25/127645.aspx
). Did you ever get the problems with ADO resolved or did
you use directory services in place of ADO to query AD?
I've used System.DirectoryServices with some success. I
have code that uses
System.DirectoryServices.DirectorySearcher and runs
several times in a row before it stops working. For
instance, I run the code and retrieve results 10 times in
a row. I then wait several minutes and attempt to run the
code again and it hangs. Eventually, the method returns a
message:

An unhandled exception of
type 'System.Runtime.InteropServices.COMException'
occurred in system.directoryservices.dll

Additional information: Unknown error (0x80005000)

I reboot my development box and the code runs fine again
(for awhile). Maybe I'm hitting a connection limit? I'm
not sure what system services (on either the client or
server side) that System.DirectoryServices depend on?
When I reboot, something is getting reset that causes the
code to run again. This is why I began looking at ADO.NET
as an alternative.

Thanks!
-----Original Message-----
¤ I am attempting to use the System.Data.OleDb namespace to
¤ connect to an Active Directory running under Win2000.
I
¤ have initialized the OleDbConnection with a connection
¤ string of "Provider=ADSDSOObject;". I have a simple query
¤ string as follows: "SELECT sAMAccountName
¤ FROM 'LDAP://mydomain.com/' WHERE objectClass = 'User'"
¤
¤ I receive an errror when I try to read the
¤ results: "OleDbDataReader result = myCommand.ExecuteReader
¤ (CommandBehavior.CloseConnection);"
¤
¤ The error states: DB_E_ERRORSINCOMMAND(0x80040E14) - An
¤ unhandled exception occurred during the execution of the
¤ current web request.
¤
¤ Any samples or suggestions are greatly appreciated.

In addition to the other suggestions, I would first try
to trap the error using Try...Catch. I
haven't heard anything that indicates that the AD
provider is not supported by the OLEDB .NET
provider.

There are different ways to query but I've typically
used the default naming context. In my instance
it's: LDAP://DC=testdomain,DC=org but you should be able
to use DirectoryServices to extract this
information.

Also, I would try removing the
CommandBehavior.CloseConnection argument to see if it
makes any
 
Roy,

Thanks for your reply. I haven't used the
System.Management object. Would I use it in a similiar
manner as System.DirectoryServices? If so, I've had some
success with that (see my post below).

Thanks!
 
Marc,

Thanks for the reply. I tried the variations on the SQL
syntax you suggested below, but had the same outcome. I
thought maybe I was experiencing a security problem, but
I would think the error returned would indicate this. I
will continue to try some other variations.

Thanks!
 
Back
Top