473,466 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Connection to MS access

1 New Member
Hi

I am a newb to perl, n m tryin to get myself familiar with the syntax n stuff. I need to connect to a database in microsoft access. I 've optiperl n activestat perl installed on my machine.. can anyone plz guide me on how to connect to access through a perl program. Also do i need to install win32::odbc or dbi drivers to connect to MS access?

Thanks in advance!!
Aug 5 '06 #1
9 25188
dhascruz
3 New Member
HI,

Using DBI you can connect the database.

1. first you create user dsn and connect your access database.
2. Download DBI module and install the module
3. Use the below code and connece the access databse


Expand|Select|Wrap|Line Numbers
  1. use DBI;
  2. use strict;
  3.  
  4.  my $dbh = DBI->connect('DBI:ODBC:test','','') or die "Cannot connect: $DBI::errstr\n";
  5.  
  6.  my $sth1 = $dbh->prepare('Select * from test');
  7.  
regards
dhascruz
Aug 7 '06 #2
ocean999
1 New Member
Hi

I am a newb to perl, n m tryin to get myself familiar with the syntax n stuff. I need to connect to a database in microsoft access. I 've optiperl n activestat perl installed on my machine.. can anyone plz guide me on how to connect to access through a perl program. Also do i need to install win32::odbc or dbi drivers to connect to MS access?

Thanks in advance!!
Hello,

Here an example to connect to MS Access with Perl:

Expand|Select|Wrap|Line Numbers
  1.     use DBI;
  2.     use STRICT;
  3.  
  4.         $sqlstatement= $txt1->get('0.0','end');
  5.  
  6.     #open connection to Access database
  7.     $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\dump9\Noordenwind.mdb');
  8.  
  9.     #prepare and execute SQL statement
  10.  
  11.     $sth = $dbh->prepare($sqlstatement);
  12.     $sth->execute ||
  13.     die "Could not execute SQL statement ... maybe invalid?";
  14.  
  15.  
  16.     #output database results
  17.  
  18.     while (@row=$sth->fetchrow_array()){
  19.     print "@row\n";
  20.        }
  21.  
Have fun.

Another Perl addict
Ocean999
Aug 8 '06 #3
nickyxu
5 New Member
Hi

I am a newb to perl, n m tryin to get myself familiar with the syntax n stuff. I need to connect to a database in microsoft access. I 've optiperl n activestat perl installed on my machine.. can anyone plz guide me on how to connect to access through a perl program. Also do i need to install win32::odbc or dbi drivers to connect to MS access?

Thanks in advance!!
Dear,

Have you finished this subject?
I am working on this program now.
I have spent the whole week to do it. But I can not find a good way.
Now I am trying to mount the remote directory.
Or, put the mdb file on the web site, and download it on local direcotry.
Obviously, both of them are not good choices.
Do you have some advice?

Thanks a lot!
I am look forward to hearing you.

Best Regards,
Xu
Sep 23 '07 #4
nickyxu
5 New Member
HI,

Using DBI you can connect the database.

1. first you create user dsn and connect your access database.
2. Download DBI module and install the module
3. Use the below code and connece the access databse



use DBI;
use strict;

my $dbh = DBI->connect('DBI:ODBC:test','','') or die "Cannot connect: $DBI::errstr\n";

my $sth1 = $dbh->prepare('Select * from test');

regards
dhascruz
I think this is only for local mdb file.
I have tried to create a data source, but Host, server, serverport doesn't work.
Maybe not, it says: Can't alloc filename
Say: My mdb file is on D:\mdb\B2000.mdb from the remote machine.
And I use: Host = server ip
database = d:\mdb\B2000.mdb
Error:Unable to locate database d:\mdb\B2000.mdb
If I made database = http://serverip/mdb/B200.mdb ( I set the virtual directory named mdb from IIS)
Error:Unable to locate database http://128.128.108.110/mdb/B2000.mdb
Sep 23 '07 #5
nickyxu
5 New Member
Hello,

Here an example to connect to MS Access with Perl:

Expand|Select|Wrap|Line Numbers
  1.     use DBI;
  2.     use STRICT;
  3.  
  4.         $sqlstatement= $txt1->get('0.0','end');
  5.  
  6.     #open connection to Access database
  7.     $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\dump9\Noordenwind.mdb');
  8.  
  9.     #prepare and execute SQL statement
  10.  
  11.     $sth = $dbh->prepare($sqlstatement);
  12.     $sth->execute ||
  13.     die "Could not execute SQL statement ... maybe invalid?";
  14.  
  15.  
  16.     #output database results
  17.  
  18.     while (@row=$sth->fetchrow_array()){
  19.     print "@row\n";
  20.        }
  21.  
Have fun.

Another Perl addict
Ocean999
This is a good example. But how to set for a remote access database?
Do you have any suggestion?

Thanks very very much!
Sep 23 '07 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
Dear,

Have you finished this subject?
I am working on this program now.
I have spent the whole week to do it. But I can not find a good way.
Now I am trying to mount the remote directory.
Or, put the mdb file on the web site, and download it on local direcotry.
Obviously, both of them are not good choices.
Do you have some advice?

Thanks a lot!
I am look forward to hearing you.

Best Regards,
Xu

I have corrected the formatting of your post. Please do not top post. Always put your reply below the post you are replying to. Otherwise,

?
about
talking
are
you
what
know
anyone
will
how


Regards,

Jeff
Sep 23 '07 #7
KevinADC
4,059 Recognized Expert Specialist
This is a good example. But how to set for a remote access database?
Do you have any suggestion?

Thanks very very much!
This is a very old thread, the people that posted before you are long gone. The code posted by ocean999 is not valid perl code and will not run. It may have some insight into your question. Even though you are using perl as the interface to the database, your question about accessing a remote access database might be best asked in the access forum. Personally I don't know the answer to your question so I will be of no further help.
Sep 23 '07 #8
nickyxu
5 New Member
Thanks a lot, everyone!
I am going crazy about this!
Thanks again...
Sep 24 '07 #9
casthescript1
1 New Member
Modification to ocean999's posting to get it work for me:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. # from http://www.thescripts.com/forum/thread520248.html
  3.  
  4. use DBI;
  5. use STRICT;
  6.  
  7. $sqlstatement= "select * from tblName;";
  8.  
  9. #open connection to Access database
  10. $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);'.
  11.       'dbq=C:\path\to\file.mde');
  12. # Note: this worked for me on a .mde file, I assume .mdb files work, too.
  13.  
  14. #prepare and execute SQL statement
  15.  
  16. $sth = $dbh->prepare($sqlstatement);
  17. $sth->execute ||
  18.       die "Could not execute SQL statement ... maybe invalid?";
  19.  
  20.  
  21. #output database results
  22.  
  23. while (@row=$sth->fetchrow_array())  {
  24.    print "@row\n";
  25. }
  26.  
  27.  
  28.  
  29.  
Hi

I am a newb to perl, n m tryin to get myself familiar with the syntax n stuff. I need to connect to a database in microsoft access. I 've optiperl n activestat perl installed on my machine.. can anyone plz guide me on how to connect to access through a perl program. Also do i need to install win32::odbc or dbi drivers to connect to MS access?

Thanks in advance!!
Oct 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
6
by: jonefer | last post by:
I have two versions of a 'Downtime Application that will run in the event that the mainframe goes down 1) SQL Server ASP.NET app (accessed outside the mainframe network) 2) MS Access Version of...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
16
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
by: =?Utf-8?B?VmVua2F0ZXNhbiBT?= | last post by:
Hi, I have a requirement of consuming a connection object returned from a COM component deployed in COM+ application. I have given the need for this requirement end of my query. My component...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.