473,799 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI program cannot access database

Hello,
I am trying to run a perl CGI program for accessing a database. The
program runs fine from command prompt, producing expected output. But it
gives errors while running as CGI.

--------- Program -------------
use DBI;
use DBD::Pg;
print "Content-type: text/plain\n\n";
$dbh=DBI->connect("dbi:P g:dbname='samik ';host='abc.org ';port=5432","s amik","xxxx");
$query="select * from temp";
$sth=$dbh->prepare($query );
$sth->execute ;
while(@data=$st h->fetchrow_array ())
{ print $data[0].", ".$data[1]."<br>\n"; }
$sth->finish;
$dbh->disconnect() ;
-------------------------------------

This was giving me the following error:
DBI connect('dbname ='samik';host=' abc.org';port=5 432','samik',.. .)
failed: could not translate host name "abc.org" to address: Unknown host
at /var/www/cgi-bin/test/dbex.pl line 6

When I replaced the host name with its IP address, I got the following
error:
DBI connect('dbname ='samik';host=' a.b.c.d';port=5 432','samik',.. .)
failed: could not create socket: Operation not permitted at
/var/www/cgi-bin/test/dbex.pl line 6

Has anyone come across this problem before? Any pointers are welcome.
Thanks for your time and regards,
-Samik

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
8 2603
* Samik Raychaudhuri <sa***@freeshel l.org> [2004-10-07 21:12:31 -0500]:
I am trying to run a perl CGI program for accessing a database. The
program runs fine from command prompt, producing expected
output. But it gives errors while running as CGI.
Has this ever worked?
$dbh=DBI->connect("dbi:P g:dbname='samik ';host='abc.org ';port=5432","s amik","xxxx");


It seems that machine can't resolve abc.org (although I can). The
format of your connect string is a little unorthodox, but it seems to
work in general.

What does 'dig abc.org' return on this machine?

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
On Fri, Oct 08, 2004 at 08:17:07AM -0700, Steven Klassen wrote:
* Samik Raychaudhuri <sa***@freeshel l.org> [2004-10-07 21:12:31 -0500]:
$dbh=DBI->connect("dbi:P g:dbname='samik ';host='abc.org ';port=5432","s amik","xxxx");


It seems that machine can't resolve abc.org (although I can). The
format of your connect string is a little unorthodox, but it seems to
work in general.

What does 'dig abc.org' return on this machine?


I wonder if "abc.org" was just an example and not the real domain
name. Samik, what's the real name? Should it be resolvable from
the public Internet?

The original message reported the following error when connecting
by IP address:

failed: could not create socket: Operation not permitted

I wonder of packet filters are preventing the PostgreSQL connection
from working, and possibly causing DNS problems as well.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
Hello,
Thanks very much for the replies. Please find follow-ups inline.

On 10/8/2004 11:05 AM, Michael Fuhr wrote:
On Fri, Oct 08, 2004 at 08:17:07AM -0700, Steven Klassen wrote:

* Samik Raychaudhuri <sa***@freeshel l.org> [2004-10-07 21:12:31 -0500]:
$dbh=DBI->connect("dbi:P g:dbname='samik ';host='abc.org ';port=5432","s amik","xxxx");

It seems that machine can't resolve abc.org (although I can). The
format of your connect string is a little unorthodox, but it seems to
work in general.

What does 'dig abc.org' return on this machine?


I wonder if "abc.org" was just an example and not the real domain
name. Samik, what's the real name? Should it be resolvable from
the public Internet?

abc.org is just an example. The real name is freesql.org, it is
resolvable from the public internet. I can also run the same program
from command prompt in Cygwin shell, and it runs fine.
The original message reported the following error when connecting
by IP address:

failed: could not create socket: Operation not permitted

I wonder of packet filters are preventing the PostgreSQL connection
from working, and possibly causing DNS problems as well.

What exactly you mean by packet filters? How do I check what packet
filters are active?
Thanks for your time.
Regards,
-Samik

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #4

On 10/8/2004 10:17 AM, Steven Klassen wrote:
$dbh=DBI->connect("dbi:P g:dbname='samik ';host='abc.org ';port=5432","s amik","xxxx");
It seems that machine can't resolve abc.org (although I can). The
format of your connect string is a little unorthodox, but it seems to
work in general.

Thanks very much for your reply. Why do you say that the connect string
is a little unorthodox? I just followed the standard DBI documentation.
Regards,
-Samik

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5
* Samik Raychaudhuri <sa***@freeshel l.org> [2004-10-08 11:37:49 -0500]:
Thanks very much for your reply. Why do you say that the connect
string is a little unorthodox? I just followed the standard DBI
documentation.


Just not used to seeing the semi-colons in the DSN. Usually the
dbname, host, and port directives are space delimited.

I didn't catch earlier that you said it works on the command line but
not as a CGI. I'll have another look at the original post.

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #6
I solved the problem, getting hints from Maarten. This is for posterity.
I looked at this thread:
http://www.cygwin.com/ml/cygwin/2004-09/msg01159.html
This thread (as well as Maarten) suggests to set/pass SYSTEMROOT
environment variable in Apache. I didn't know how to do that, googling
helped. This is what I did:
I added the following lines in httpd.conf
<IfModule mod_env.c>
PassEnv SYSTEMROOT
</IfModule>
Scripts are running fine now.
References:
1. http://httpd.apache.org/docs/mod/mod_env.html#passenv
2. http://httpd.apache.org/docs/env.html

Thanks again to all who replied.
Regards,
-Samik

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #7
On Fri, Oct 08, 2004 at 11:35:34AM -0500, Samik Raychaudhuri wrote:
On 10/8/2004 11:05 AM, Michael Fuhr wrote:

failed: could not create socket: Operation not permitted

I wonder of packet filters are preventing the PostgreSQL connection
from working, and possibly causing DNS problems as well.

What exactly you mean by packet filters? How do I check what packet
filters are active?


Packet filters are a firewalling mechanism -- they can be configured
to allow or prohibit certain network traffic. How to check on them
is system-dependent.

I didn't notice that you said the script ran successfully from the
command line; that makes it less likely that a firewall was interfering
because if that were the case, the script would probably fail under
all circumstances. Since you've reported that you solved the
problem, the packet filter hypothesis can be dismissed.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #8
On Fri, Oct 08, 2004 at 10:09:13AM -0700, Steven Klassen wrote:
* Samik Raychaudhuri <sa***@freeshel l.org> [2004-10-08 11:37:49 -0500]:
Thanks very much for your reply. Why do you say that the connect
string is a little unorthodox? I just followed the standard DBI
documentation.


Just not used to seeing the semi-colons in the DSN. Usually the
dbname, host, and port directives are space delimited.


Perl DBI uses a different format to the usual libpq one. It's
documented in DBD::Pg.

http://search.cpan.org/~rudy/DBD-Pg-..._Class_Methods

-Dom

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2769
by: A P | last post by:
I am planning to migrate my exisiting MS Access program that uses yes/no fields (checkbox). Can ASP identifies checkbox field of ms access? I am planning to use the same database and use msacess for report generation and web browser for encoding to the database. Hope you could help me. Me
2
2133
by: Jay Chan | last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that has Windows-2003 Server on it. Now, we cannot get access to that database server from other computers. Seem like this may be an issue with Active Directory. Our network consists of Windows-2000 Servers (SP 4) and Windows-2000 workstations and Windows-XP workstations. We also have SQL Server 2000 (SP2) in three Windows-2000 servers. All work fine. Recently, we get a...
8
5483
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
6
2592
by: Stefania Scott | last post by:
Hi, I need to find how can I know that a program I am going to shell it is already open. This program uses an csv file that I need to refresh before shelling the program, however if the csv file is already in use because the program is open I cannot refresh it (kill it and rewrite it) and I do not get any error message. Right now I have a message the prompts the user to close the robot software before opening it through the database. Is...
51
5092
by: John Baker | last post by:
Hi: Some time ago I developed a program in Access, and separated the database and the program itself (using the normal access tools).We have the db on our server and the programin the desktop system. I have modified the program a number of times, and now find that I need to change the DB slightlt. This appears to require that I REMERGE the data base and program, and I have no idea how to do that. Can someone give me some pointers,...
1
2042
by: gaosul | last post by:
I am non-programming scientist and I am using a Program called Easyarticles from Synaptosoft Inc., which is based the database program Access. Unfortunately, the owner of this company has disappeared even though his website still functions. As the program requires updating, I was wondering whether anyone has any suggestions, as to what I should do. The program allows you to search a public database called PubMed. You can mark abstracts...
2
2146
by: jannordgreen | last post by:
I try to run http://localhost/scroller/scrollertest.asp in my IE 6 browser. The asp program tries to connect to a MS Access 97 database. The program works when the database is sitting on any local drive, but when I put it on a network drive I get this error message: Error Type: Microsoft JET Database Engine (0x80004005)
14
1718
by: c676228 | last post by:
Hi everyone, Our site is down, because of our hosting company applied sql server 2000 sp4 on windows 2000 server. right after it applied the service pack, our sql server database is down and no conn etc. When one technical support restart the server, the obejcts like tables in database cannot be recognized from our asp pages anymore, data cannot be inserted into any database table and data cannot be
22
60291
Frinavale
by: Frinavale | last post by:
How To Use A Database In Your Program Many .NET solutions are database driven and so many of us often wonder how to access the database. To help you understand the answer to this question I've provided the following as a quick example of how to retrieve data from a database. In order to connect to a SQL Server Database using .NET you will need to import the System.Data.SqlClient package into your program. If you are not connecting to a...
9
2921
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading the text files from the watched folder line by line into variables and then posting them to a SQL table. All of the code for the form is shown below. And it works fine except for 2 issues. First issue: In the Finally of the Try for teh SQL...
0
9687
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10252
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.