use DBI; our $db; our %sp; sub open_db { return if $db and $db->{'Active'}; Log "\nConnecting to the database"; eval { $db = DBI->connect('dbi:ODBC:Driver=SQL Server;Server=JobVIPeR;Database=XxxXXXxX', 'xxx', 'xxx', {PrintError => 0,RaiseError => 1,LongReadLen => 65536,AutoCommit => 0}); }; if (! $db) { Log("\tCannot connect to the database! : $DBI::errstr"); return; } Log "\tConnected"; prepare_sps(); } sub prepare_sps { $sp{SetDirty} = $db->prepare('EXEC dbo.SetInt ?, 1'); #... } #... $sp{SetDirty}->execute($objname."_dirty"); #... #### my $import = $db->prepare_cached('EXEC dbo.ImportClient ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?'); db_error("compiling ImportClient",$db) if !$import; my $WasNew = 0; $import->bind_param_inout( 15, \$WasNew, 1); #... my $id = 0; $import->bind_param(++$id, $_) for @{$rec->{fields}}{@fields}; if ($import->execute()) { if ($WasNew) { $new++; } else { $updated++; } } else { db_error("updating client '$rec->{fields}->{client_desc}'",$db,1); $import->finish(); $incorrect++; } #...