I have a series of Stored Procedures in an MS SQL database. These stored procedures are executed in turn without any problems when executed from within SQL Query Analyzer. Like so:
EXEC Reception 'DSR', 'EuropeanStandard', 'Intentional self-harm', 1, +'MF', 1, 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul', 'nul +', 'nul', 'nul', 'nul', 0, 1990, 2002, 0, 74, 'Community', 'Community + name', 'Town name', 3, 'DKaReTinnvzEHNPbskwFqukPioqrDwJrkDBJ'

But, when I run the same EXEC statement from a Perl program via an ODBC connection, the process starts to proceed as normal, but then stalls half way through. I really have no idea where to start looking. The process was working fine previously with Perl activation and I have only made small changes to the SPROC code since then. I have pin pointed where the stalling occurs and cannot find an error with the T-SQL code. Anyway, as I have said, it works well when not activated by the perl program. The Perl program that does the activation is as follows. Does anyone have any ideas what could be going wrong? NB. I don't think that the problem is with the Perl code. That has not changed since it was working before.

#! perl -w scipt use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; #use vars qw(@row_) = (); my ($data_source, $database, $user_id, $password) = qw(ip_address data +base_name user_name password ); 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 $inputfile = $ARGV[0]; my $outputfile = $ARGV[1]; my $Request_id; my $Variable_number; my $Variable; my $Choice; my @VARIABLE; my @CHOICE; my $Command; my $Return_results; my $SPROC; my $unique; my $elements_in_array; my $Component_number_old = 1; my $Component_number = 1; #my $flat_file = "Flat_file_test_C.txt"; my $flat_file = $inputfile; open (FLAT_FILE, "<$flat_file"); while (<FLAT_FILE>){ chomp; s/"//g; # This " is generated by excel when there is a comma in th +e line that is printed by excel $Component_number_old = $Component_number; if ($_ =~ /^$/) { last; } elsif ($_ =~ /SPROC\sName\:\s([a-z|A-Z|0-9|_]{1,100})/){ print "Hi_A\n"; $SPROC = $1; } elsif ($_ =~ /^\*(.{36});(\d{1,5});(\d{1,5});([a-z|A-Z|0-9|_]{1,50}) +;(.{1,150})/){ print "$_\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); print "Hi_B\n"; $unique = $1; $Component_number = $2; $elements_in_array = $3; $Variable = $4; $Choice = $5; } elsif ($_ =~ /^\*(.{36})\;(\d{1,5})\;(\d{1,5})\;([a-z|A-Z|0-9|_]{1,5 +0})\;$/){ print "$_\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); print "Hi_B\n"; $unique = $1; $Component_number = $2; $elements_in_array = $3; $Variable = $4; $Choice = "NULL"; } if ($_ =~ /^\sEND/){ print "Hi_E\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); $Command = join(' ', 'EXEC', $SPROC, join(', ', @CHOICE[1 .. $elements_in_array])) . ';'; my $Request_id = $CHOICE[$elements_in_array]; print "$Command\n"; Got_Command($Command, $Request_id, $outputfile); undef @CHOICE; my @CHOICE; } } close FLAT_FILE; sub Got_Command { my($Command_B,$Request_id_B, $outputfile_B) = @_; open (OUTPUT_FILE, ">>", $outputfile_B) or die "Unable to open $outputfile: $^E\n"; print "Hi_F\n"; print "$outputfile\n"; print "$Command_B\n"; my $sthB_A = $dbh->do($Command_B) or die "Couldn't do query: ".$dbh +->errstr; my $Return_results = "Select DISTINCT Colls FROM Database"; print "$Return_results"; my $sth_C = $dbh->prepare($Return_results) or die "Couldn't prepare +query: ".$dbh->errstr; $sth_C->execute() or die "Couldn't execute query: ".$sth_C->errstr; while (my @row = $sth_C->fetchrow_array) { print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~\n"; print join("\t", @row); print "\n"; print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~\n"; print OUTPUT_FILE join("\t", @row); print OUTPUT_FILE "\n"; undef @row; } }

In reply to Perl activation of MS SQL SPROCS 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.