Monday, March 26, 2012

Openquery and ADSI Problem

I am trying to run a query in an ASP.NET application against Active Director
y
using a linked server (ADSI) in SQL Server 2000. The query runs without any
problems in Query Analyzer:
SELECT
sAMAccountName
FROM
OPENQUERY
(
ADSI,
'
SELECT
sAMAccountName
FROM
''LDAP://ADSERVER/ DC=ourdomain,DC=com''
WHERE
MemberOf=''cn=GroupName ,OU=ourOUname,DC=ourdomain,DC=com'' AND
sAMAccountName=''username''
'
);
The query will simply return a username if that user belongs to the
specified group. Once again, this works fine in Query Analyzer, but it does
not return any results in my ASP.NET application. I am using SQLConnection,
SQLCommand, and SQLDataReader objects. I have also tried this with generic
odbc objects, but to no avail.
I have found that the query executes in ASP.NET if I remove the MemberOf
section of the WHERE clause in the query.
Has anyone come across something like this before? Any help would be
appreciated.
Many Thanks,
JimSometimes these types of problems (works in XYZ program but not from
ASP.NET) arise because the ASPNET account does not have the same
permissions as the user running XYZ program. Are you connecting to the
database as the ASPNET account?
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 29 Oct 2004 10:05:03 -0700, "James Schuler" <James
Schuler@.discussions.microsoft.com> wrote:

>I am trying to run a query in an ASP.NET application against Active Directo
ry
>using a linked server (ADSI) in SQL Server 2000. The query runs without an
y
>problems in Query Analyzer:
>SELECT
> sAMAccountName
>FROM
> OPENQUERY
> (
> ADSI,
> '
> SELECT
> sAMAccountName
> FROM
> ''LDAP://ADSERVER/ DC=ourdomain,DC=com''
> WHERE
> MemberOf=''cn=GroupName ,OU=ourOUname,DC=ourdomain,DC=com'' AND
> sAMAccountName=''username''
> '
> );
>The query will simply return a username if that user belongs to the
>specified group. Once again, this works fine in Query Analyzer, but it doe
s
>not return any results in my ASP.NET application. I am using SQLConnection
,
>SQLCommand, and SQLDataReader objects. I have also tried this with generic
>odbc objects, but to no avail.
>I have found that the query executes in ASP.NET if I remove the MemberOf
>section of the WHERE clause in the query.
>Has anyone come across something like this before? Any help would be
>appreciated.
>Many Thanks,
>Jim

0 comments:

Post a Comment