ksublondie has asked for the wisdom of the Perl Monks concerning the following question:
and the resulting log output:print "Connecting to sql db..."; my $db=DBI->connect('DBI:ODBC(AutoCommit => 0):DB') or handleError({Er +rorMessage=>'DB Error'.DBI->errstr.$!,Subject=>"Transaction Import Er +ror"}); print "done\nPreparing command..."; my $statement = $db->prepare("Insert INTO Transactions VALUES (?,?,?,c +onvert(date,?),convert(date,?),?,?,?,?,?,?,?,?,?,?,?,?,?,?)") or hand +leError({ErrorMessage=>'DB Error'.DBI->errstr.$!,Subject=>"Transactio +n Import Error"}); print "Getting data\n"; my $lineno=0; while ( my $line=$csv->getline($io)){ ++$lineno; my @thisline=@{$line}; push @thisline,$thisline[13]-$thisline[16]+$thisline[17]; print join(',',@thisline)."\n"; $statement->execute(@thisline) or handleError({ErrorMessage=>'DB E +rror'."\n".$DBI::errstr."\n".$DBI::err."\n".$DBI::state."\n".$!,Subje +ct=>"GL Transaction Import Error"}); print "$lineno\n"; } $db->commit(); $db->disconnect();
Connecting to sql db...done Preparing command...Getting data 0,10001,0,2015-10-05 12:00 AM,,74,6928.14,,POD 9085-9086 00010001 +00,,I,,7576.07,7576.07,,0,6182.34,7363.14,8756.87 1 0,10001,0,2015-10-05 12:00 AM,,44,2027.06,,POD 9075-9076 00010001 +00,,I,,7576.07,7576.07,,0,6182.34,7363.14,8756.87 calling handleError calling sendEmail Creating email...done
The email says:
So it's inserting line 1, but failing on line 2. Although the content is different between line 1 & line 2, the format and length is essentially identical. If I copy/paste the command and values into management studio, the command succeeds.DB Error [Microsoft][ODBC SQL Server Driver]String data, right truncation (SQL- +22001) 1 22001 Result too large
Any ideas why line 1 inserts, but crashes on line 2?
UPDATE: I have modified my input file a few times, playing with the line order (ie, copy/paste line 1 so lines 1 & 2 are identical data, cut/paste line 1 down in the file, etc). No matter the data, line 1 imports, but line 2 always fails. Since it's a server 2012 box, could it be a driver issue perhaps???
UPDATE 2: I moved the $db->prepare statement from before the while loop to inside the while loop and it works. ...Of course, this defeats the purpose of prepare and execute which I've been able to do successfully in the past. Really looking like a driver issue at this point.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::ODBC insert first line, but not line 2
by jfroebe (Parson) on Oct 06, 2015 at 19:42 UTC | |
by ksublondie (Friar) on Oct 06, 2015 at 20:11 UTC | |
|
Re: DBD::ODBC insert first line, but not line 2
by mje (Curate) on Oct 12, 2015 at 10:30 UTC |