I have a cgi that calls posts data to MS SQL db. Most of the time this works fine but just recently i have begun to put a large amount of data into one field and it is now error'ing out with the following error.
DBServer = 'XXXXXXXXX1' Database = 'db_XXXX' User = 'user' DB_Error_Msg = '[Microsoft][ODBC SQL Server Driver]String data, right truncation (SQL-22001)(DBD: st_execute/SQLExecute err=-1)
the code i use to connect to set the database connection up is as follows,
In reply to:
my $DSN = "driver={SQL Server};Server=$server;database=$database;uid=$username;pwd=$password;";
my $data_source = "$source:$DSN";
my $db_user = xxxxxx;
my $db_pwd = xxxxxx;
my ($data_source, $db_user, $db_pwd) = @_;
$dbh = DBI->connect($data_source, $db_user, $db_pwd, { RaiseError => 0, AutoCommit => 1 }) || reportError("CMF", "ERROR", "2", "Database connection error : " . $DBI::errstr . " DBServer = '$server' Database = '$database' User = '$username'");
# Need to make the default length of the returned field larger. default is 80 chars.
$dbh->{LongReadLen} = 1000000;
# Truncate everything over 1000000 ($dbh->{LongReadLen}) or it will error out.
$dbh->{LongTruncOk} = 1;
the code that gets called that generates the error is
In reply to:
$Stmt = "execute usp_update_ipr_by_job_id_nr ?, ?, ?, ?, ?, ?, ?, ?, ?, ?;";
$sth = $dbh->prepare_cached($Stmt) || return;
$sth->bind_param(1, $JobId);
$sth->bind_param(2, $JobCreator);
$sth->bind_param(3, $IprName);
$sth->bind_param(4, $IprDescription);
$sth->bind_param(5, $IprRationale);
$sth->bind_param(6, $IprImplications);
$sth->bind_param(7, $IprSource);
$sth->bind_param(8, $TargetLiveDate);
$sth->bind_param(9, undef);
$sth->bind_param(10, undef);
$rv = $sth->execute();
any ideas as to what could cause the error
String data, right truncation as i was under the impression
$dbh->{LongReadLen} = 1000000;
# Truncate everything over 1000000 ($dbh->{LongReadLen}) or it will error out.
$dbh->{LongTruncOk} = 1;
would handle anything that was too large for the database to handle.
Cheers,
Hazzie
HazzieTS 5.5.2 on NT.