473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Querying AD using vb script from ASP page returns "An operations error occurred"

Hi,

I am trying to query AD for sAMAccountName attribute for given email.
My code is as follows:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ldapSearchBaseDn,ldapSearchHost,ldapUser,ldapPwd    
  3.  
  4. ldapSearchBaseDn = "dc=test,dc=com"  ''"base dn"    
  5. ldapSearchHost = "IP of domain system"    
  6. ldapUser    = "domain\username"
  7. ldapPwd     = "password"
  8. email  = "test@testmail.com"
  9. Set oConn = Server.CreateObject("ADODB.Connection")
  10.  
  11. oConn.Provider = "ADSDSOObject"
  12. oConn.properties("User ID") = ldapUser
  13. oConn.properties("Password") = ldapPwd
  14. oConn.Properties("Encrypt Password") = true    
  15. oConn.Open "Ads Provider"  
  16.  
  17. Set rs = oConn.Execute("<LDAP://" & ldapSearchHost & "/" & ldapSearchBaseDn &">;" &_
  18.  "(&(objectClass=user)(mail=" & email & "));" &_
  19.   "sAMAccountName;subtree")    
  20.  
  21.  
When I am running the above code as vbs file, my code is running without any issue and returning sAMAccountName for given email.
But when I am running same query from ASP page, then I am getting following Error:
Error# -2147217865
Error Desc= An operations error occurred
Error Source - Active Directory

Please help me in solving the above issue. Its very urgent.

Thanks,
Anu
Jul 11 '11 #1
6 11572
jhardman
3,406 Expert 2GB
The problem is probably that the iusr account doesn't have access to AD. When you run it from a .vbs file you are probably executing it yourself, so it runs under your username. Go into IIS and (if you dare) set the asp process to run under your user account instead of iusr. I bet that will fix the problem.

Jared
Jul 11 '11 #2
Thanks for reply.
I am member of "domain Admin" group in AD.
I have to run this query without changing IIS settings.
I have tried the same in 2 different systems
1.Error "Table does not existss" if I run same query from asp page published in windows2003
2. "Operation error occured" if I run from windows2008 system

Does it make any difference? As I am getting different error when running in windows2003 system.
I had run same query successfully a long time back from windows2003 system.

Thanks,
Anu
Jul 11 '11 #3
jhardman
3,406 Expert 2GB
The bottom line is there is nothing wrong with the script, the problem is the account the script uses when it executes. It does not run under your user credentials, it runs as a service account called "iusr_(computername)". That account doesn't usually have very many permissions, and it isn't a member of the AD.

I don't know of any way to do this without changing IIS settings. I guess you could try to add the iusr account to the domain, but I've never tried that, not sure if it can work. You could also try increasing iusr's permissions.

Jared
Jul 11 '11 #4
Hi jhardman,

My website is published in IIS7.0 in windows2008 system.
The main IIS settings are:
Authentication - Anonymous
Authorization rules - allow all
.Net trust levels - full
The Application Pool settings are as below:
Managed Pipeline Mode - Integrated
Identity - LocalSystem
Load User Profile - false

Please advise ,What do I need to change in above settings to run my script?

Thanks,
Anu
Jul 12 '11 #5
jhardman
3,406 Expert 2GB


go into IIS (type inetmgr into the run prompt)
select your server
double click on authentication
right click on "anonymous authentication"
select "edit" and you will see the above image
click on "set..." to change user

Let me know if this works.

Jared
Jul 14 '11 #6
Hi Jared,

I need not to make any changes in IIS and I get solution with following script:
Expand|Select|Wrap|Line Numbers
  1. ldapSearchBaseDn =  "dc=abc,dc=com"     
  2. ldapSearchHost =  "AD IP"    
  3. ldapUser         = "AD User"
  4. ldapPwd         = "password"   
  5. email              = "abc@xyz.com"
  6.  
  7. strQuery = "<LDAP://"& ldapSearchHost & "/" & ldapSearchBaseDn &">;" &_
  8. "(&(objectCategory=user)(mail=" & email & "));" &_
  9. "samAccountName;" &_
  10. "subtree"
  11.  
  12. Const ADS_CHASE_REFERRALS_SUBORDINATE = &H20
  13.  
  14. 'Start the ADO connection
  15. Set oConnection1 = CreateObject("ADODB.Connection")
  16. Set objCommand = CreateObject("ADODB.Command")
  17. oConnection1.Provider = "ADsDSOObject"
  18. oConnection1.Properties("User ID") = user
  19. oConnection1.Properties("Password") = pwd
  20. oConnection1.Properties("Encrypt Password") = True
  21. oConnection1.Open "ADsDSOObject"
  22. objCommand.ActiveConnection = oConnection1objCommand.CommandText = strQuery
  23. objCommand.Properties("Cache Results") = False
  24. objCommand.Properties("Chase Referrals") = ADS_CHASE_REFERRALS_SUBORDINATE
  25.  
  26. Set rs = objCommand.Execute
  27. Set objCommand = nothing
  28.  
  29. If Err.Number = 0 then    
  30. if not rs.eof then
  31.     user = trim(rs("sAMAccountName").value)
  32. end if
  33. end if
  34.  

But now I have one more issue. I have created one file test.txt in c:\windows\temp folder. I am trying to read that file. But when i check for its existence, its returning me false i.e. file does not exists.
My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Dim fileName,fso
  2. ForReading = 1
  3. fileName="C:\WINDOWS\Temp\MacList.txt"
  4.  
  5. set fso=Server.createobject("scripting.FileSystemObject")
  6.  
  7. If fso.FileExists(fileName) then
  8.   //code to handle it
  9. else
  10.  //file not exists
  11. end if
  12.  
  13.  
and above code is returning that file does not exists.
Please help.

Thanks
Anu
Jul 19 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stan | last post by:
Ocasionally I get this error message: "A severe error occurred on the current command. The results, if any, should be discarded" There is an arcticle in MSDN describing this problem, but it...
1
by: timVerizon | last post by:
Hoping someone can help here.. Our application (C#.Net) was receiving IBM.Data.DB2.DB2Exceptions ERROR SQL0904N Unsuccessful execution caused by an unavailable resource. Reason code: '', type...
1
by: Angel | last post by:
I'm trying to connect to a fixed IP address (eg. http://10.60.903.50/TempFile) in order to retrieve one accii line of text in TempFile. I try to read the information with this code: string...
0
by: David Mediavilla | last post by:
I am writing a client for an HTTPS web service using WSE 1.0 but I always get an error like "The underlying connection was closed: An unexpected error occurred on a send." Sometimes the error...
2
by: mike_li | last post by:
On Window 2000 Professional Server DB2 UDB Level: DB2 code release "SQL07029" with level identifie "030A0105" and informational tokens "DB2 v7.1.0.98", "n040510" and "WR21337". In the...
0
by: pinky | last post by:
Hi all I am having one web service where in at a time of calling one webmethod through client application i am continuously getting following error :- The underlying connection was...
11
by: MLH | last post by:
Private Sub ButtonP_Click() On Error GoTo Err_ButtonP_Click Dim ThisForm As String ThisForm = Me.Name Exit_ButtonP_Click: Exit Sub Err_ButtonP_Click: Dim r As String, k As String, Message3...
2
by: jj555s | last post by:
I get a Message that says "No error occured." when I tried to write in a file. What does it mean?
0
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have a bitmap which I have retreived through the WebBrowser DrawToBitmap method into a Bitmap. When I try to save the bitmap I get "ExternalException occurred A generic error occurred in...
0
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I want to get MAC address of client machine. I am using folllowing code in asp using vbscript: Set objWshShell = Server.CreateObject("WScript.Shell") strToExec = "nbtstat -a " &...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.