Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl/DBI/FreeTDS/SQLAzure忽略了一些插入_Perl_Azure Sql Database_Dbi_Freetds - Fatal编程技术网

Perl/DBI/FreeTDS/SQLAzure忽略了一些插入

Perl/DBI/FreeTDS/SQLAzure忽略了一些插入,perl,azure-sql-database,dbi,freetds,Perl,Azure Sql Database,Dbi,Freetds,我在Perl使用DBI和FreeTDS(在Ubuntu上)将一些数据插入SQLAzure时遇到了间歇性问题。问题可能会出现,一些行会被忽略,然后我就可以毫无问题地再次运行它 脚本: print "Importing File $file: to Staging Table\n"; open my $info, $file or die "Could not open $file: $!"; $dbh->do("EXEC DWTOOLS.InitStage;") or die $D

我在Perl使用DBI和FreeTDS(在Ubuntu上)将一些数据插入SQLAzure时遇到了间歇性问题。问题可能会出现,一些行会被忽略,然后我就可以毫无问题地再次运行它

脚本:

print "Importing File $file: to Staging Table\n";
    open my $info, $file or die "Could not open $file: $!";

$dbh->do("EXEC DWTOOLS.InitStage;") or die $DBI::errstr ; #truncates the table

    my $sth = $dbh->prepare("INSERT INTO DWSTAGE.CDRImport (LINE) VALUES(?);") or die $DBI::errstr ;
    my $counter = 0;
    while( my $line = <$info>)  {
            $line =~ s/\r?\n$//;
            $counter++;
    print "Loading line $counter: $line\n" ;
            my $rc = $sth->execute($line) or die $DBI::errstr ;
            print "Result: $rc\n";
    }
    close $info;


print "\nChecking Data Warehouse: $counter lines expected\n" ;
my $checksth = $dbh->prepare("EXEC DWTOOLS.CheckStage ?;") or die $DBI::errstr ;
    my $checkrc = $checksth->execute($counter) or die $DBI::errstr ;

my @row;
while ( @row = $checksth->fetchrow_array(  ) ) {
    print "Row: @row\n";
}
因此,当我查看该表时,它显示所有开始行都丢失了,直到它开始工作时的某一点-可靠地-直到结束-所以基本上,文件的最后35行被加载,它们从1开始,一直到35行,其中第1行实际上是第(166-35+1)行或其他行。Azure中的表有一个PK、clustered IDENTITY列,它从1开始,没有间隙,所以就像第一个这么多插入被删除,没有任何错误迹象。这种情况发生在各种文件、各种大小和文件中的不同位置

文件在循环中处理,每个文件都被打开、处理和关闭,以防与这种奇怪的行为有任何关系。该语句将为每个文件重新准备一次,但如果可能会导致问题,则在程序的整个生命周期内都将保持SQL Azure连接。如果出现连接故障,我仍然希望程序会死掉,但是从执行过程中返回的错误代码的缺乏来看,我不相信我会得到任何错误的迹象

如果我继续重新运行程序,所有的行都进来了,一切都很好


我不确定得出什么结论。现在,我的结论是FreeTDS有缺陷且不可靠。

看起来DB似乎在truncate进程完成之前执行insert。如果这是一个存储过程,您可以添加某种标志,表明它已完成,并在继续之前检查它。或者最好还是将整个数据库调用集合包装到一个事务中。

您是否需要在某个地方执行$dbh->commit()?好吧,已经很久了,我放弃了从Linux访问该数据库的尝试。我想,如果连接允许同时执行多个操作,并且在第一个存储过程完成之前返回,那么这是可能的。它在Windows上没有这个问题。
Importing File filename: to Staging Table
Loading line 1: data redacted
Result: 1
Loading line 2: data redacted
Result: 1
etc. etc. with no indication of errors
Loading line 165: data redacted
Result: 1
Loading line 166: data redacted
Result: 1

Checking Data Warehouse: 166 lines expected
Row: 35 166
Row: 35 166
Loading to Data Warehouse