first script failing to connect

Created a test db in access and placed it on the root of a network drive, which is partitioned into 3 drives one for users which is what I'm using, drive letter 'H'

#!/usr/bin/perl
# load module
use DBI;

# connect
my $dbh = DBI->connect("DBI:ODBC:dbname=Test; host=H", "Username", "password",  {'RaiseError' => 1});

# execute INSERT query
my $rows = $dbh->do("INSERT INTO pets (species, name) VALUES ('parrot', 'Polly')"); print "$rows row(s) affected\n";

# execute SELECT query
my $sth = $dbh->prepare("SELECT species, name FROM pets"); $sth->execute();

# iterate through resultset
# print values
while(my $ref = $sth->fetchrow_hashref()) { print "$ref->{'name'} is a $ref->{'species'}\n"; }

# clean up
 $dbh->disconnect();

this is the result when run

C:\Perl\eg>test1.pl
DBI connect('dbname=Test;host=H','username',...) failed: [Microsoft][ODBC Driver
 Manager] Data source name not found and no default driver specified (SQL-IM002)
(DBD: db_login/SQLConnect err=-1) at C:\Perl\eg\test1.pl line 6
deNZityAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FishMongerCommented:
The host needs to be the hostname or IP address of the server, not the drive letter.  
0
deNZityAuthor Commented:
Thanks for the reply, I put in the IP address and got the same result.

D
0
clockwatcherCommented:

my $dbh = DBI->connect("DBI:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=h:\test.mdb","","");

where h:\test.mdb is the path to your access database.

Or define a System DSN with ODBC Data Source Admin and use the data source name you defined.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

clockwatcherCommented:
Sorry forgot to escape the '\'  

   my $dbh = DBI->connect("DBI:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=h:\\test.mdb","","");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahoffmannCommented:
you have not installed the proper DBI driver module
0
deNZityAuthor Commented:
Thanks for the replies,
clockwatcher followed your suggestion and got


C:\Perl\eg>perl test1.pl
DBD::ODBC::db do failed: [Microsoft][ODBC Microsoft Access Driver] Record(s) can
not be added; no insert permission on 'pets'. (SQL-42000)(DBD: Execute immediate
 failed err=-1) at test1.pl line 9.
DBD::ODBC::db do failed: [Microsoft][ODBC Microsoft Access Driver] Record(s) can
not be added; no insert permission on 'pets'. (SQL-42000)(DBD: Execute immediate
 failed err=-1) at test1.pl line 9.

Looks like the connection is ok I just have to sort the permissions, which is a bit strange as I'm connecting as the same user as
when I created the db.
0
clockwatcherCommented:
What kind of security do you have set up on your database?  Unless you've added user security to your access database (which would make it easy to explain -- but is doubtful since few people use that feature of access and you'd know you had if you had), the primary reason I can think of that would cause that error is that the account running the script (not whatever user you're using in the ODBC parameter setup) but the actual account the script is running under doesn't have write access to the directory housing the access database.  Access has to create/modify a locking file (.ldb) in the directory that holds the database.  If it can't, the database will be read only.
0
deNZityAuthor Commented:
Clockwatcher points to you. I can see I'm going to have to find some basic perl
tutorials dealing with database connections and data extraction, any resources
you could point me towards would be appreciated.

D
0
clockwatcherCommented:
Shoot.  I'm not gonna be much help on this one.  I don't have any real good links to share.  I always fall back to the documentation whenever I use DBI:  perldoc DBI
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.