OS: Windows 7
Perl: 5.14.2 via Strawberry Perl
I am trying to write a simple Perl script to read in a .csv file and import it into an Access 2010 (.accdb) file. Try as I may, I cannot get my perl script to connect to the database file. Relevant code is below:
#!C:/strawberry/perl/bin/perl.exe
use strict;
use DBI;
use Text::CSV;
use Win32::OLE;
my $DBFile = "KosJourney.accdb";
my $DBHandle = DBI->connect("dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0
+;Data Source=$DBFile;Persist Security Info=False;") or die $DBI::errs
+tr;
.....
open my $FILEHANDLE,$FilePath or die "Failure opening CSV file for rea
+ding: " . $!;
while (<$FILEHANDLE>)
{
chomp;
next if /Last Name/;
my ($LastName,$FirstName,$GUID) = split (/\t/,$_);
$LastName =~ s/"//g;
$FirstName =~ s/"//g;
$GUID =~ s/"//g;
my $FullName = $FirstName . " " . $LastName;
my $InsertUserQuery = "INSERT INTO Users (Username,FullName,FirstN
+ame,LastName) VALUES (?,?,?,?);";
&Echo("Executing SQL: " . $InsertUserQuery);
my $InsertUserResult = $DBHandle->prepare($InsertUserQuery);
$InsertUserResult->execute($GUID,$FullName,$FirstName,$LastName);
}
close $FILEHANDLE;
The error follows:
DBI connect('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=KosJourney.
+accdb;Persist Security Info=False;','',...) failed: Can't Open Connec
+tion 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=KosJourney.accdb;
+Persist Security Info=False;'
Package : DBD::ADO::dr
Filename : C:/strawberry/perl/vendor/lib/DBD/ADO.pm
Line : 158
Last error : -2146824582
OLE exception from "ADODB.Connection":
Provider cannot be found. It may not be properly installed.
Win32::OLE(0.1709) error 0x800a0e7a
in METHOD/PROPERTYGET "Open" at PopulateUsersFromResultCSV.pl line 21
Can't Open Connection 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=K
+osJourney.accdb;Persist Security Info=False;'
It is the connection string throwing the exception. I have access 2010 installed. I'm not sure if it is necessary but I have also installed MDAC (http://www.microsoft.com/en-us/download/confirmation.aspx?id=5793) as well as
Microsoft Access Database Engine 2010 Redistributable (http://www.microsoft.com/en-us/download/details.aspx?id=13255). The weird thing is, this exact setup is working just fine on other computers (which are identical in
configuration and hardware). The .adddb file is sitting next to this script into the same folder, to eliminate path issues. All of the modules noted in the code have been successfully installed via CPAN.
I have and still am scouring the web for help on this, so far nothing has been forthcoming.
Note that I don't really care how the connection is made, I am using DBI because that is what I am familiar with. I do not have a DSN set up on my local machine but I didn't beleive that to be necessary.
Any help anyone can offer will be really appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.