CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
DBI connect error when connecting to SQLite in windows

 



kwatts59
Novice

Aug 15, 2014, 3:11 PM

Post #1 of 2 (13272 views)
DBI connect error when connecting to SQLite in windows Can't Post

To All,
I am getting the following error when I try to connect to my SQLite database:

DBI connect('dbname=C:SERSKENNETHDESKTOPSQLITE_DBASESBRC.DB','',...) failed: unable to open database file at sqlite test2.pl line7.

Below is the entire program

Code
use DBI; 
print "Connecting to database\n";
$dbh = DBI -> connect("DBI:SQLite:dbname=C:\Users\Kenneth\Desktop\sqlite_dbases\abrc.db","","");
$query1 = "select locus_id from abrc";
$sqlquery1 = $dbh->prepare($query1) or die "Cannot prepare query \n";
$rv1 = $sqlquery1->execute or die "Cannot execute query \n";
@row = $sqlquery1->fetchrow_array();
$sqlquery1->finish;
print "Finished\n";


When I remove the path "C:\Users.." as shown below

$dbh = DBI -> connect("DBI:SQLite:dbname=abrc.db","","");

The error goes away, but it uses the wrong abrc.db file.

Any help will be appreciated.


FishMonger
Veteran / Moderator

Aug 15, 2014, 4:47 PM

Post #2 of 2 (13268 views)
Re: [kwatts59] DBI connect error when connecting to SQLite in windows [In reply to] Can't Post

The \ backslash is the escape character. You need to either double them up to escape them or use single quotes.

Code
$dbh = DBI -> connect("DBI:SQLite:dbname=C:\\Users\\Kenneth\\Desktop\\sqlite_dbases\\abrc.db","","");



Code
$dbh = DBI -> connect('DBI:SQLite:dbname=C:\Users\Kenneth\Desktop\sqlite_dbases\abrc.db',"","");


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives