Has anyone ever produced anything like the following, and has got MS SQL 2000 to accept the requests that are submitted. Without error messages like:
DBD::ODBC::db do failed: [Microsoft][ODBC SQL Server Driver][SQL Serve +r]Line 567: Incorrect syntax near 'GO'. (SQL-42000)(DBD: Execute imme +diate failed err=-1) at Run_required_SPROCS.pl line 97, <FILE> line 9 +35. <code>
The code:
#! perl -w use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; my ($data_source, $database, $user_id, $password) = qw(127.0.0.1 not_t +elling not_telling not_telling ); # This ip address is an address tha +t is common to all computers and therefore is a perminant ip address my $conn_string = "driver={SQL Server}; Server=$data_source; Database= +$database; Trusted_Connection=yes"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my @files; my $line; my $file; while (<*.sql>) { next if $_ eq 'Activate.sql'; $file = $_; open (FILE, "$file"); my $line_number = 0; my $run; LINE: while (<FILE>){ my $line = $_; $line_number = $line_number +1; $run = 1; if ($line_number == 1){ $run = 0 if $line !~ m/^ALTER\sPROCEDURE\s/; last LINE; } else { $run = 1; } last LINE; } if ($run == 1){ push (@files, $file); } else { #Do nothing } } print "@files"; my $line_B; my $FH; my $batch; foreach my $filename ( @files ) { open ( FILE, "<", $filename ) or die( "Couldn't open $filename: $!" ); my $batch = ""; INNER: while ((<FILE>)) { # s/ALTER\bPROCEDURE/CREATE PROCEDURE/; $batch .= $_; last INNER if eof || m/^\s*go\s*$/i; } # print $batch; # sleep 5; $dbh->do($batch) if ($batch =~ m/\s*go\s*$/msi); #http://perldoc.pe +rl.org/perlre.html }
Update: By the way. This program now works very well when the SPROCS are already present but does not work when I want to create new SPROCS. Never mind.

In reply to DBD::ODBC error by Win

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.