473,574 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ 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 25195
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:O DBC:test','','' ) or die "Cannot connect: $DBI::errstr\n" ;

my $sth1 = $dbh->prepare('Selec t * 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.md b from the remote machine.
And I use: Host = server ip
database = d:\mdb\B2000.md b
Error:Unable to locate database d:\mdb\B2000.md b
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
16490
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 Win2K3/IIS6.0), do we still need this patch? 2) Does it specifically solve only this error: The underlying connection was closed. An unexpected error
6
1679
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 the same app locally installed (C Drive) Can someone help me with the 'Catch' part of this code in VB.NET? Pseudo code
14
3486
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, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that...
8
9619
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 work from
16
2859
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 a worker thread that would execute the db commands. The pool was fixed and all the connections were created when the db access class was...
20
3257
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 many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I...
7
13532
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 the error "ExecuteReader requires an open and available Connection. The connection's current state is Open, Executing." I do not use ExecuteReader,...
6
8147
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru...
1
3418
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 returns a Connection objec to ASP page and then I am trying to use the same Connection object to Command/Recordset object to execute a SP I am...
0
7807
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8241
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6456
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5624
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5301
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3742
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2249
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 we have to send another system

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.