Jenda,

I was puzzled why it worked for you, but not for me, so I tried your sub
pretty-exactly... and it worked...

The only difference in my code that I could see was that I was using a
Trusted Connection instead of Standard Authentication, ie:

THIS:        my $dbh = DBI->connect("dbi:ODBC:Driver={SQL
Server};Server=myserver;Trusted_Connection=yes;",
NOT THIS:  my $dbh = DBI->connect('dbi:ODBC:louise', 'sa', 'mypwd',

So I tried it with trusted connection and didn't work.... then I
realized, that I was passing the attribute hash as the second parameter
to the 'connect' method... (you don't need the second and third params
with trusted connections'... so I placed null markers for second and
third params... and bang... now it works!!!

Thanks for all your help.... working snippet below...note the empty uid
and pwd slots...

L
******************************
        # my $dbh = DBI->connect('dbi:ODBC:louise', 'sa', '$mypwd',
          my $dbh = DBI->connect("dbi:ODBC:Driver={SQL
Server};Server=$myserver;Trusted_Connection=yes;",'','',
                {PrintError => 0,RaiseError => 1,LongReadLen => 65536,
                odbc_async_exec => 1,
                odbc_err_handler => sub {
                                my ($state, $msg) = @_;
                                # Strip out all of the driver ID stuff
                                $msg =~ s/^(\[[\w\s]*\])+//;
                                $text .= $msg."\n";
                                return 0;
                        }
                });



-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 09, 2003 05:36 AM
To: [EMAIL PROTECTED]
Subject: Re: SQL Server- DBD::ODBC - getting results not rows - question
about earlier post


From: "Mitchell, Louise M" <[EMAIL PROTECTED]>
> In an earlier post inquiring about how to get the results ( such as 
> from a backup or dbcc ), rather than rows, the response pasted below 
> indicated a solution.... however, when I try this, I find that the 
> actual results are returning in STDERR, not in the variable $text....

That's strange. It does work for me.

> In my code, I redirect STDERR to a file, as well as STDOUT...
> printing the variable always prints a null string... while the file
> containing the STDERR always has the results...
> 
> This is the case if it's an error ( I forced one for a backup command 
> )... or if it's just results ( I ran a simple dbcc checkdb )...

Could you post a small complete script that shows this problem?

This is the exact code I use (except the username&password of 
course;)

sub DBCC {
        my $database = shift();
        my $text = '';

        my $dbh = DBI->connect('dbi:ODBC:jobodbc2', 'uid', 'pwd',
                {PrintError => 0,RaiseError => 1,LongReadLen => 65536,
                odbc_async_exec => 1,
                odbc_err_handler => sub {
                                my ($state, $msg) = @_;
                                # Strip out all of the driver ID stuff
                                $msg =~ s/^(\[[\w\s]*\])+//;
                                $text .= $msg."\n";
                                return 0;
                        }
                });

        my $sth = $dbh->prepare("dbcc CHECKDB ('$database')");
        $sth->execute;
        $dbh->disconnect();

        return $text;
}

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

Reply via email to