I learing DBI. Connect to SQLServer 2008 is sucessful,but one sth(statement handle) is active ,and another stn execut,there is something wrong as follows:
DBD::ODBC::st execute failed: [Microsoft][SQL Server Native Client 10. +0] busy connection result another command (SQL-HY000) at dumpTableInf +oColumn.pl line 33
my script as follows:
#!/usr/bin/perl -w # # ch06/tabledump: Dumps information about all the tables. use strict; use DBI; ### Connect to the database my $dbh = DBI->connect( "dbi:ODBC:SQLSERVER2008R2","sa","7354500", { RaiseError => 1 }); ### Create a new statement handle to fetch table information my $tabsth = $dbh->table_info(); ### Iterate through all the tables... while ( my ( $qual, $owner, $name, $type ) = $tabsth->fetchrow_array() + ) { ### The table to fetch data for my $table = $name; ### Build the full table name with quoting if required $table = qq{"$owner"."$table"} if defined $owner; ### The SQL statement to fetch the table metadata my $statement = "SELECT * FROM $table"; print "\n"; print "Table Information\n"; print "=================\n\n"; print "Statement: $statement\n"; ### Prepare and execute the SQL statement my $sth = $dbh->prepare( $statement ); $sth->execute(); #Attention the error my $fields = $sth->{NUM_OF_FIELDS}; print "NUM_OF_FIELDS: $fields\n\n"; print "Column Name Type Precision Scale Nul +lable?\n"; print "------------------------------ ---- --------- ----- --- +------\n\n"; ### Iterate through all the fields and dump the field information for ( my $i = 0 ; $i < $fields ; $i++ ) { my $name = $sth->{NAME}->[$i]; ### Describe the NULLABLE value my $nullable = ("No", "Yes", "Unknown")[ $sth->{NULLABLE}->[$i +] ]; ### Tidy the other values, which some drivers don't provide my $scale = $sth->{SCALE}->[$i]; my $prec = $sth->{PRECISION}->[$i]; my $type = $sth->{TYPE}->[$i]; ### Display the field information printf "%-30s %5d %4d %4d %s\n", $name, $type, $prec, $scale, $nullable; } ### Explicitly deallocate the statement resources ### because we didn't fetch all the data $sth->finish(); } exit;

In reply to DBI sth can't run simultaneously for SQLServer 2008 by Thai Heng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.