I am using the Win32::ODBC module to connect to a SQL server and insert data into tables. It all works fine but I get occasional insert errors that I want to trap. I then use DUMPDATA to try and capture specific SQL insert errors and this also works fine. however, I cannot get the DUMPDATA info into my LOGFILE. I open a LOGFILE and write all pertinent messages here from the start of program but the DUMPDATA insists on going to STDOUT. I have tried many different ways to correct this but have been unsuccessful.
Here is only partial code, the important pieces. It should make sense to anyone who has done this. It is the DUMPDATA piece that I want to send to LOGFILE. This example does not work.
Any help would be great. Thanks so much.
Here is only partial code, the important pieces. It should make sense to anyone who has done this. It is the DUMPDATA piece that I want to send to LOGFILE. This example does not work.
Code:
if (!($db=new Win32::ODBC("Driver={SQL Server};Server=$newdb;Database=$dbname;uid=$uid;pwd=$pw"))) {
...(then later on in the code after connection successful etc.)
if ($db->Sql($sql_statement)) {
print (LOGFILE "Win32 error is \"Win32::ODBC::Error()\"\n");
my ($err) = $db->Error;
my ($dumpdata) = $db->DumpData();
$dumpmsg = sprintf("DUMPDATA: %150s", $dumpdata);
print (LOGFILE "\n$dumpmsg\n\n");
} else {
print (LOGFILE "SQL Insert: Error=None\n"); $sql_success++; } #-end if/ else
Any help would be great. Thanks so much.