Skip Menu |

This queue is for tickets about the DBD-ADO CPAN distribution.

Report information
The Basics
Id: 96558
Status: open
Priority: 0/
Queue: DBD-ADO

People
Owner: sgoeldner [...] cpan.org
Requestors: ASB [...] cpan.org
Cc: dbi-users-help [...] perl.org
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.99
Fixed in: (no value)



CC: dbi-users-help [...] perl.org
Subject: Error restoring database - although everything works fine
Hi! When I restore a database, an error is reported although everything works fine. The databae is restored. Is this a problem of DBD::ADO or do I have to investigate somewhere else? I attached a script for reproduction. It restores a test.bak file and throws an error. The result is the following output to the command line: Name "Win32::OLE=HASH(0x3aae8cc)::LastError" used only once: possible typo at /< D:\error-on-restore.exe>DBD/ADO/Const.pm line 31. DBD::ADO::db do warning: Can't Execute 'RESTORE DATABASE [test] FROM DISK = N'D: \test.bak' WITH FILE = 1, MOVE N'test' TO N'D:\data\test.mdf', MOVE N'test_log' TO N'D:\logs\test_log.ldf', REPLACE' Package : DBD::ADO::db Filename : /<D:\error-on-restore.exe>DBD/ADO.pm Line : 983 Description : 328 Seiten wurden f³r die test-Datenbank, Datei 'test' f³r Datei 1, verarbeitet. HelpContext : HelpFile : NativeError : 4035 Number : Source : Microsoft OLE DB Provider for SQL Server SQLState : 01000 at error-on-restore.pl line 45. Error restoring database: Can't Execute 'RESTORE DATABASE [test] FROM DISK = N'D :\test.bak' WITH FILE = 1, MOVE N'test' TO N'D:\data\test.mdf', MOVE N'test_log' TO N'D:\logs\test_log.ldf', REPLACE' Package : DBD::ADO::db Filename : /<D:\error-on-restore.exe>DBD/ADO.pm Line : 983 Description : 328 Seiten wurden f³r die test-Datenbank, Datei 'test' f³r Datei 1, verarbeitet. HelpContext : HelpFile : NativeError : 4035 Number : Source : Microsoft OLE DB Provider for SQL Server SQLState : 01000 at error-on-restore.pl line 45. Sorry for the German, it's a German OS. Here is some details: OS: Windows Server 2012 DB: MS SQL Server 2012 Perl: 5.16.3 x86m from ActiveState
Subject: error-on-restore.txt
#!perl use strict; use warnings; use DBI; use DBD::ADO; use Data::Dumper qw/Dumper/; =comment Reproduction program. Triggers an error message when a backup is restored using an SQL command. The error occurres in the line startig with $dbh->do($restore_sql) Database: MS SQL Server 2012 =cut my $host = '192.168.0.48'; my $user = 'your-username'; my $auth = 'your-secret-password'; my $database = 'master'; # dropping requires using master db # build DSN in a somewhat ugly way my $dsn = "Provider=sqloledb;Trusted Connection=yes;"; $dsn .= "Server=$host;Database=$database"; # connect my $dbh = DBI->connect( "dbi:ADO:$dsn", $user, $auth, { PrintError => 0, RaiseError => 0, AutoCommit => 1}, ) or die "Database connection not made: $DBI::errstr"; # drop the database if it already exists my $drop_sql = q~IF EXISTS (SELECT name FROM sys.databases WHERE name = N'test') DROP DATABASE [test]~; $dbh->do($drop_sql) or die "Error dropping database: " . $dbh->errstr; # restore the database from a backup my $restore_sql = q~RESTORE DATABASE [test] FROM DISK = N'D:\test.bak' WITH FILE = 1, MOVE N'test' TO N'D:\data\test.mdf', MOVE N'test_log' TO N'D:\logs\test_log.ldf', REPLACE~; $dbh->do($restore_sql) or die "Error restoring database: " . $dbh->errstr; # Close the connection $dbh->disconnect(); exit(0);
This is a warning, not an error. Both are mixed in DBI (similar to SUCCESS_WITH_INFO in SQL). You can check $dbh->err for real errors. But I wouldn't use $dbh->do(...) or die ... IMHO, exception handling is much easier to use. You can control the behavior with RaiseError, PrintError, PrintWarn in a declarative way and omit all (or most) error handling code.