[Israel.pm] Connecting through IIS to SQL Server with Windows Authentication

Yossi Klein kleinyossi at yahoo.com
Tue Jan 24 06:08:04 PST 2012


I am trying to run a 
Perl CGI script that connects to a SQL Server. 

Webserver = IIS 6.0 (running on MS Windows Server 2003 - SP2)

SQL Server =  Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64)   Mar 29 2009 10:11:52   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: )   (running on MS Windows Server 2008 R2 Enterprise)

Perl =  ActiveState 5.8.3 (Yes, I know that there are newer versions, but I'm not in control of when upgrades happen and unless I have a good reason to upgrade, which of course also requires regression testing, I'd prefer not to).


What I'm trying to do is to pass the Windows Authentication information to the SQL Server so 
that the person running the CGI script has the appropriate permissions in the db. The problem 
is that the the auth information is not being pass through: 
 
The error I'm getting is:

 
[Microsoft][ODBC SQL Server Driver][SQL 
Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. (SQL-28000)


 
Does anybody have 
any ideas or experience with this kind of set-up?


Here's a test program that fails:

##############
use DBI;
use CGI qw(:all);

print "Content-type: text/html\n\n";
print "<HTML>\n";

my %attr = (PrintError => 0, RaiseError => 0, AutoCommit => 1);

my $dsn =
  "DBI:ODBC:DRIVER=SQL Server;Trusted_Connection=Yes;APP=MyApp;SERVER=jacob";

#$dsn =~ s/trusted_Connection=yes;/UID=sa;PWD=xxxxxx;/i;

my $dbh = DBI->connect($dsn, undef, undef, \%attr);

if (!defined $dbh)
    { $dbh = DBI->errstr; }

print "$dbh\n";
print "</HTML>\n";
################


If I comment out the line of code above that turns the connection into untrusted (and I fix the password, of course :-), the program successfully connects.


Thanks,

Yossi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20120124/551453a4/attachment.htm 


More information about the Perl mailing list