Posts

Showing posts with the label Active State

Real simple to connect to MSSQL from Perl

Again, this took me a little while but here I am. Connecting to a database ( SQL SERVER 2008 ) from a Windows Server 2008 VM I own ( thanks TECH ED 2008 ) and Active State Perl. Install Scite cos it's a nice editor and you are away laughing... #!/usr/bin/perl use DBI; my $DSN = 'driver={SQL Server};Server=localhost; database=AdventureWorks;TrustedConnection=Yes'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; my $sth = $dbh->prepare('select top 10 * from Sales.vSalesPerson') or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute(); while( @data = $sth->fetchrow_array()) { foreach(@data) { print "[$_]"; } print "\n\n"; } $sth->finish; $dbh->disconnect; Results: C:\Users\dave\Documents>perl perl1.pl [268][][Stephen][Y][Jiang][][North American Sales Manager][238-555-0197][stephen 0@adventure-works.com][0][2427 Notre Dame Ave.][][Redmond]...