Solved

cgi script fails until refreshed in IE - then it works

Posted on 2004-08-05
9
328 Views
Last Modified: 2008-01-09
The script works fine if you hit refresh after it errors out. This website is hosted on an Intranet webserver running IIS 6 and Windows 2003 Server. The version of Perl on the server is 5.8.4. My code is passed a username from an html page (theLookupID) and searches Active Directory for a username and prints out their fullname as well as user id. Here is the code:

####################################
use Win32::OLE qw (in);
use CGI qw(:standard);
print header;
print start_html('Active Directory query results');

my $theLookupID = param('theLookupID');

my $strName    = $theLookupID;
my $strBase    = "<LDAP://ou=my,dc=foo,dc=bar,dc=com>;"; # BaseDN should be the search base
my $strFilter  = "(&(objectCategory=user)(samaccountname=$strName));";           # Valid LDAP search filter
my $strAttrs   = "AdsPath,cn;";         # Comma-seperated list
my $strScope   = "Subtree";             # Should be on of Subtree, Onelevel or Base

my $oUser;

use Win32::OLE;
$Win32::OLE::Warn = 3;
my $objConn = Win32::OLE->CreateObject("ADODB.Connection");
$objConn->{Provider} = "ADsDSOObject";
$objConn->Open;
my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope);
$objRS->MoveFirst;
while (not $objRS->EOF) {
    print $objRS->Fields(1)->Value," - ";
    $strLdap = $objRS->Fields(0)->Value;
    $oUser = Win32::OLE->GetObject("$strLdap");
    print "$oUser->{samaccountname}<br>";
    $objRS->MoveNext;
}

print end_html;

#############################################

Any ideas?
0
Comment
Question by:concept99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 20

Expert Comment

by:jmcg
ID: 11732883
You should probably mention exactly what error is reported and whether there's any useful information to be found in the web server logs.

You have two copies of the "use Win32::OLE" statement with different parameters. Maybe you should just have one?

I'm just guessing, since there's not much to go on.
0
 
LVL 3

Author Comment

by:concept99
ID: 11734360
I removed the second Win32::OLE.

Also, here is the error message I receive on the webpage:
###############
Table does not exist. Win32::OLE(0.1701) error 0x80040e37 in METHOD/PROPERTYGET "Execute" at D:\www\infra\cgi-bin\lookup.pl line 35 Content-Type: text/html; charset=ISO-8859-1
###############


Also, nothing relating to this in the webserver logs.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 11745137
This message is complaining about something on line 35 of a file named lookup.pl -- the file you showed us doesn't have as many as 35 lines in it.

The "table does not exist" error would indicate that you may have spelled something wrong -- but I'm still just guessing.Why would it fail some of the time and work other times?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:concept99
ID: 11747031
Sorry about that, I removed some commented lines from the script. Here is what line 35 is:

my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs . $strScope);

0
 
LVL 20

Expert Comment

by:jmcg
ID: 11749599
It makes sense that it would be that line.

I googled the error number and the error message (something you might want to try, too) but I didn't find anything that enlightened me about how this script of yours could both work and not work.

Before I throw my hands up in the air and say I can't help you, I'll throw out a couple more possibilities:

1) have you looked at the Net::LDAP module?

http://search.cpan.org/~gbarr/perl-ldap-0.3202/

It looks to me that this module may simplify the overall LDAP interaction, if what you're doing is fairly routine.

2) is it possible you have two LDAP servers, one with the data you want and one without?

0
 
LVL 3

Author Comment

by:concept99
ID: 11752208
I did do a google search and found the following:
http://support.microsoft.com/default.aspx?scid=kb;en-us;296254

This could be a solution to my problem, but I was curious to see if anyone else had experienced this type of issue.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 11753274
Possibly, but like the other mentions I found with Google, there were all sorts of suggestions for things to try if your lookup always failed -- but you say it works some of the time.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11989666
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to search multiple patterms in a file with perl? 4 87
Transforming a Soap message to a simple xml message! 10 167
Perl tar error 8 74
Perl Versus AWK? 7 97
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question