Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using the below code and i am getting error. How to solve this? i cannot understand this error also.

DBD::DBM::st execute failed: Cannot open .\Reference.lck: No such fil +e or directory at C:/Perl/lib/DBD/File.pm line 574. [for Statement " Select * from Reference"] at DataBaseControl.pl line 22. DBD::DBM::st execute failed: Cannot open .\Reference.lck: No such fil +e or directory at C:/Perl/lib/DBD/File.pm line 574. [for Statement " Select * from Reference"] at DataBaseControl.pl line 22.
use strict; use warnings; use DBI; my ($dbh, $sth); my $Error_Message = "\nThere Was A Problem Connecting To The Database\ +n"; my $driver = 'DBM'; # e.g., mysql or ODBC or ??? my $dbusername = 'sa'; my $dbpassword = 'admin'; my $server = 'localhost'; my $database = 'Copyediting'; $dbh = DBI->connect("dbi:$driver:$database:$server", $dbusername, $dbp +assword, {'RaiseError' => 1, 'PrintError' => 1} ) || die "$Error_Message $DBI::errstr"; $dbh->{RaiseError} = 1; for my $sql( split /;\n+/," Select * from Reference; "){ my $sth = $dbh->prepare($sql); $sth->execute; $sth->dump_results if $sth->{NUM_OF_FIELDS}; } $dbh->disconnect();

Also i don't what driver needs to specify here? I have the below driver in my system using this code.
@driver_names = DBI->available_drivers;

DBM ExampleP File ODBC Proxy SQLite Sponge mysql

Replies are listed 'Best First'.
Re: sql server database connectivity error
by cdarke (Prior) on Sep 21, 2009 at 10:53 UTC
    You have to decide which database system to use in order to decide on a driver. The title of your question says "sql server database", and if it is Microsoft's SQL Server product which you are using then you need a driver for that product. There is a discussion here: DBD module for Microsoft SQL Server.
Re: sql server database connectivity error
by roboticus (Chancellor) on Sep 21, 2009 at 17:34 UTC
    Selvakumar:

    Of the listed drivers in the end of your question, I'd use ODBC. I use it to access both MS SQL and Oracle databases with no issues.

    ...roboticus

      ODBC adds a lot of overhead, and does not offer all of the features you could use with a native driver. I would always try to connect to the database using a native driver (there are lots of native DBDs on CPAN), then fall back to the fat and slow ODBC. For MS SQL, you are right, ODBC is the way with the least pain, since there is no real native driver. You could also use ADO, which adds even more overhead, or you could try DBD::Sybase plus FreeTDS: MS SQL Server is a fork of Sybase 4.2, and they still share their communication protocol.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)